From 4982614d578bb3ae2924b78b07b1b722fbc27abc Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 22 May 2017 09:06:24 +0300 Subject: [PATCH] Remove duplicated sample code in leak.md * doc/leak.md (Example): Remove code snippets which are similar to that of include/leak_detector.h and leak_test.c; replace GC_find_leak=1 with GC_set_find_leak(1). --- doc/leak.md | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/doc/leak.md b/doc/leak.md index 9af33e87..e24652c4 100644 --- a/doc/leak.md +++ b/doc/leak.md @@ -65,45 +65,15 @@ the aid of a debugger. ## An Example -The following header file `leak_detector.h` is included in the "include" -subdirectory of the distribution: - - - #define GC_DEBUG - #include "gc.h" - #define malloc(n) GC_MALLOC(n) - #define calloc(m,n) GC_MALLOC((m)*(n)) - #define free(p) GC_FREE(p) - #define realloc(p,n) GC_REALLOC((p),(n)) - #define CHECK_LEAKS() GC_gcollect() - +The `leak_detector.h` file is included in the "include" subdirectory of the +distribution. Assume the collector has been built with `-DFIND_LEAK`. (For newer versions -of the collector, we could instead add the statement `GC_find_leak = 1` as the -first statement in `main`. - -The program to be tested for leaks can then look like: - - - #include "leak_detector.h" - - main() { - int *p[10]; - int i; - /* GC_find_leak = 1; for new collector versions not */ - /* compiled with -DFIND_LEAK. */ - for (i = 0; i < 10; ++i) { - p[i] = malloc(sizeof(int)+i); - } - for (i = 1; i < 10; ++i) { - free(p[i]); - } - for (i = 0; i < 9; ++i) { - p[i] = malloc(sizeof(int)+i); - } - CHECK_LEAKS(); - } +of the collector, we could instead add the statement `GC_set_find_leak(1)` as +the first statement in `main`. +The program to be tested for leaks can then look like "leak_test.c" file +in the "tests" subdirectory of the distribution. On an Intel X86 Linux system this produces on the stderr stream: -- 2.40.0