From: Ivan Maidanski Date: Tue, 7 Mar 2017 16:23:49 +0000 (+0300) Subject: Workaround 'memory leak: result' cppcheck false error (POSIX) X-Git-Tag: v8.0.0~881 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1eb21fa5caf6ad8a221610bfc72121bcca00275a;p=gc Workaround 'memory leak: result' cppcheck false error (POSIX) The report is a false positive because result (returned by mmap) should be equal to start_addr (passed to mmap). * os_dep.c [USE_MUNMAP && !USE_WINALLOC] (GC_unmap, GC_unmap_gap): Call GC_noop1(result) if CPPCHECK (same as for LINT2). * os_dep.c [USE_MUNMAP && !USE_WINALLOC && NACL] (GC_remap): Likewise. --- diff --git a/os_dep.c b/os_dep.c index 08872a08..9e4a077d 100644 --- a/os_dep.c +++ b/os_dep.c @@ -2469,7 +2469,7 @@ GC_INNER void GC_unmap(ptr_t start, size_t bytes) zero_fd, 0/* offset */); if (result != (void *)start_addr) ABORT("mmap(PROT_NONE) failed"); -# ifdef LINT2 +# if defined(CPPCHECK) || defined(LINT2) /* Explicitly store the resource handle to a global variable. */ GC_noop1((word)result); # endif @@ -2525,7 +2525,7 @@ GC_INNER void GC_remap(ptr_t start, size_t bytes) zero_fd, 0 /* offset */); if (result != (void *)start_addr) ABORT("mmap as mprotect failed"); -# ifdef LINT2 +# if defined(CPPCHECK) || defined(LINT2) GC_noop1((word)result); # endif # else @@ -2585,7 +2585,7 @@ GC_INNER void GC_unmap_gap(ptr_t start1, size_t bytes1, ptr_t start2, zero_fd, 0/* offset */); if (result != (void *)start_addr) ABORT("mmap(PROT_NONE) failed"); -# ifdef LINT2 +# if defined(CPPCHECK) || defined(LINT2) GC_noop1((word)result); # endif GC_unmapped_bytes += len;