summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2022-10-31 10:13:55 -0600
committerAaron Ball <nullspoon@oper.io>2022-10-31 10:13:55 -0600
commit2056e1a2ec447cc0e9378d33667a6f26685725a0 (patch)
treebfe134015462c95de3318c76dbf955c6722f731c
parent0c7882aab7869730680dc6d4c99a8f17dccf7d0c (diff)
downloadleak-utils-2056e1a2ec447cc0e9378d33667a6f26685725a0.tar.gz
leak-utils-2056e1a2ec447cc0e9378d33667a6f26685725a0.tar.xz
Add balloon program
This adds the balloon program, which balloons up in size immediately, taking the specified amount of memory.
-rw-r--r--Makefile7
-rw-r--r--src/balloon.c47
2 files changed, 52 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 554b146..a7669b5 100644
--- a/Makefile
+++ b/Makefile
@@ -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();
+}

Generated by cgit