[LLVMbugs] [Bug 16730] New: Static analyzer incorrectly reports leaks when realloc fails

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jul 29 06:03:01 PDT 2013


            Bug ID: 16730
           Summary: Static analyzer incorrectly reports leaks when realloc
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: labath at google.com
                CC: klimek at google.com, llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130729/51f694b8/attachment.html>

More information about the llvm-bugs mailing list