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

            Bug ID: 16730
           Summary: Static analyzer incorrectly reports leaks when realloc
                    fails
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

$ cat leak.c
#include <stdlib.h>

void Realloc(void** memory) {
  *memory = malloc(47);
  char* new_memory = realloc(*memory, 47);
  if (new_memory != NULL) {
    *memory = new_memory;
  }
}

$ ~/llvm/build/bin/clang --analyze leak.c
leak.c:9:1: warning: Potential memory leak
}
^
1 warning generated.


The problem with the above warning is that even if the realloc fails, the first
allocated block of memory will still be addressable by *memory (which will be
available to the caller). Therefore, this should not be reported as leaked.

-- 
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