aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tests/qemu/init.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-11-03 19:22:13 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-11-10 15:49:28 +0900
commit218824866beb9669e198101c7fda4c8bcce7c11c (patch)
tree8e3870f2537766da144c5b58ec5794e41681e636 /src/tests/qemu/init.c
parentnetlink: plug memory leak (diff)
downloadwireguard-monolithic-historical-218824866beb9669e198101c7fda4c8bcce7c11c.tar.xz
wireguard-monolithic-historical-218824866beb9669e198101c7fda4c8bcce7c11c.zip
qemu: check for memory leaks
Diffstat (limited to '')
-rw-r--r--src/tests/qemu/init.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tests/qemu/init.c b/src/tests/qemu/init.c
index afbc611..8f46e6c 100644
--- a/src/tests/qemu/init.c
+++ b/src/tests/qemu/init.c
@@ -17,6 +17,7 @@
#include <sys/ioctl.h>
#include <sys/reboot.h>
#include <sys/utsname.h>
+#include <sys/sendfile.h>
#include <linux/random.h>
#include <linux/version.h>
@@ -207,6 +208,28 @@ static void ensure_console(void)
panic("Unable to open console device");
}
+static void check_leaks(void)
+{
+ int fd;
+
+ if (mount("none", "/sys/kernel/debug", "debugfs", 0, NULL) < 0)
+ return;
+ fd = open("/sys/kernel/debug/kmemleak", O_WRONLY);
+ if (fd < 0)
+ return;
+ pretty_message("[+] Scanning for memory leaks...");
+ sleep(2); /* Wait for any grace periods. */
+ write(fd, "scan\n", 5);
+ close(fd);
+
+ fd = open("/sys/kernel/debug/kmemleak", O_RDONLY);
+ if (fd < 0)
+ return;
+ if (sendfile(1, fd, NULL, 0x7ffff000) > 0)
+ panic("Memory leaks encountered");
+ close(fd);
+}
+
int main(int argc, char *argv[])
{
seed_rng();
@@ -216,6 +239,7 @@ int main(int argc, char *argv[])
kmod_selftests();
enable_logging();
launch_tests();
+ check_leaks();
poweroff();
return 1;
}