Files
linux-kernel-module-cheat/userland/c/memory_leak.c
Ciro Santilli 六四事件 法轮功 fffc8d92da memory leak example
2019-09-18 00:00:02 +00:00

24 lines
401 B
C

/* https://cirosantilli.com/linux-kernel-module-cheat#memory-leaks */
#include <stdlib.h>
void * my_malloc(size_t n) {
return malloc(n);
}
void leaky(size_t n, int do_leak) {
void *p = my_malloc(n);
if (!do_leak) {
free(p);
}
}
int main(void) {
leaky(0x10, 0);
leaky(0x10, 1);
leaky(0x100, 0);
leaky(0x100, 1);
leaky(0x1000, 0);
leaky(0x1000, 1);
}