Workaround 'resource leak' error reported by cppcheck (tools, test)
authorIvan Maidanski <ivmai@mail.ru>
Thu, 13 Oct 2016 08:33:17 +0000 (11:33 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 13 Oct 2016 08:33:17 +0000 (11:33 +0300)
* 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
tools/if_not_there.c

index 1261e9c..6a97200 100644 (file)
@@ -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) );
 }
index c0f095d..652126d 100644 (file)
@@ -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);
     }