From 88990a302569d211c718f33411d51c7e638f5abf Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 13 Oct 2016 11:33:17 +0300 Subject: [PATCH] Workaround 'resource leak' error reported by cppcheck (tools, test) * tests/test.c [GC_GCJ_SUPPORT && TEST_WITH_SYSTEM_MALLOC] (reverse): Call GC_noop1 for malloc() result. * tools/if_not_there.c (main): Move "f" local variable assignments outside conditional expression. --- tests/test.c | 2 +- tools/if_not_there.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test.c b/tests/test.c index 1261e9c9..6a97200d 100644 --- a/tests/test.c +++ b/tests/test.c @@ -361,7 +361,7 @@ sexpr reverse1(sexpr x, sexpr y) sexpr reverse(sexpr x) { # ifdef TEST_WITH_SYSTEM_MALLOC - malloc(100000); + GC_noop1(GC_HIDE_POINTER(malloc(100000))); # endif return( reverse1(x, nil) ); } diff --git a/tools/if_not_there.c b/tools/if_not_there.c index c0f095d0..652126d4 100644 --- a/tools/if_not_there.c +++ b/tools/if_not_there.c @@ -16,8 +16,14 @@ int main(int argc, char **argv) DIR * d; #endif /* __DJGPP__ */ if (argc < 3) goto Usage; - if ((f = fopen(argv[1], "rb")) != 0 - || (f = fopen(argv[1], "r")) != 0) { + + f = fopen(argv[1], "rb"); + if (f != NULL) { + fclose(f); + return(0); + } + f = fopen(argv[1], "r"); + if (f != NULL) { fclose(f); return(0); } -- 2.40.0