diff --git a/config/config.xml b/config/config.xml index 4368cb7..b29030d 100644 --- a/config/config.xml +++ b/config/config.xml @@ -28,6 +28,6 @@ mypool - enable + disable diff --git a/memory/alloc_dispatch.c b/memory/alloc_dispatch.c index 6b9ab79..ad4b9c9 100644 --- a/memory/alloc_dispatch.c +++ b/memory/alloc_dispatch.c @@ -84,7 +84,7 @@ void *nMalloc(size_t size, const char * filename, const char *func, int line){ return NULL; } - fprintf(fp, "[+] [%s : %s : %d] %p: %ld malloc\n", filename, func, line, ptr, size); + fprintf(fp, "[+] [%s:%d:%s] [%p:%ld]\n", filename, line, func, ptr, size); fflush(fp); fclose(fp); diff --git a/memory/leak_detect/bpftrace b/memory/leak_detect/bpftrace new file mode 100755 index 0000000..f0f073f Binary files /dev/null and b/memory/leak_detect/bpftrace differ diff --git a/memory/leak_detect/memleak.bpf b/memory/leak_detect/memleak.bpf new file mode 100644 index 0000000..40be359 --- /dev/null +++ b/memory/leak_detect/memleak.bpf @@ -0,0 +1,36 @@ +BEGIN +{ + printf("Start memory leakage detect\n"); +} + +uprobe:/home/lian/share/9.1-kvstore/kvstore:nMalloc +{ + @tmp_size[tid] = arg0; + @tmp_file[tid] = str(arg1); + @tmp_func[tid] = str(arg2); + @tmp_line[tid] = arg3; +} + +uretprobe:/home/lian/share/9.1-kvstore/kvstore:nMalloc +{ + $ptr = retval; + + if ($ptr != 0) { + @allocs[$ptr] = ( @tmp_file[tid], @tmp_line[tid], @tmp_func[tid], @tmp_size[tid]); + } + + delete(@tmp_size[tid]); + delete(@tmp_file[tid]); + delete(@tmp_func[tid]); + delete(@tmp_line[tid]); +} + +uprobe:/home/lian/share/9.1-kvstore/kvstore:nFree +{ + delete(@allocs[arg0]); +} + +END +{ + printf("\n=== Memory Leaks ===\n"); +} \ No newline at end of file