http://llvm.org/bugs/show_bug.cgi?id=19585

            Bug ID: 19585
           Summary: Memory leak with realloc() not reported.
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

#include <stdlib.h>

int
main (void)
{
    void* memory = malloc (20);
    memory = realloc (memory, 40);
    if (memory)
       free (memory);
    return 0;
}

Possible outcome:
malloc() works and returns value.
realloc() fails and overwrites pointer to first allocation.
Since realloc() doesn't free pointer to original memory, the original malloc()
is leaked.

The analyzer correctly warns that memory might leak.

But if "if (memory)" is removed (resulting in an unconditional free()), the
warning disappears.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to