diff options
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | src/balloon.c | 47 |
2 files changed, 52 insertions, 2 deletions
@@ -1,7 +1,10 @@ -all: memleak +all: memleak balloon clean: - rm -vf memleak + rm -vf memleak balloon memleak: cc --std=gnu99 -O2 -Wall src/memleak.c -o memleak + +balloon: + cc --std=gnu99 -O2 -Wall src/balloon.c -o balloon diff --git a/src/balloon.c b/src/balloon.c new file mode 100644 index 0000000..769af90 --- /dev/null +++ b/src/balloon.c @@ -0,0 +1,47 @@ +/** + * Balloon leaks the specified amount of memory all at once + * Copyright (C) 2022 Aaron Ball, nullspoon@oper.io + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <signal.h> +#include <string.h> + +char* BUF; + +void handler(int sig) { + printf("\nFreeing memory\n"); + free(BUF); + exit(128); +} + +int main(int argc, char* argv[]) { + long max = 0; + signal(SIGINT, handler); + + if(argc == 1) { + printf("Baloon memory amount required in MB\n"); + return 1; + } + max = strtol(argv[1], NULL, 10) * 1024 * 1024; + printf("Allocating %s MB of space\n", argv[1]); + + BUF = malloc(max); + memset(BUF, 1, max); + printf("Done. Press Ctrl+c to free memory.\n"); + pause(); +} |