[LLVMbugs] [Bug 13674] New: realloc() failures are falsely reported to leak original pointer

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Aug 22 19:51:06 PDT 2012


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

             Bug #: 13674
           Summary: realloc() failures are falsely reported to leak
                    original pointer
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: jeremy at goop.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 9099
  --> http://llvm.org/bugs/attachment.cgi?id=9099
Source showing instance of the problem

In code which uses realloc(), it falsely reports the original buffer to be
leaked on the realloc failure path.  For example, this code:


#include <stdlib.h>

struct thing {
    char *data;
    int len;
    int off;
};

int append(struct thing *t, char c)
{
    if (t->len == t->off) {
        char *n = realloc(t->data, t->len + 100);
        if (n == NULL)
            return -1;
        t->data = n;
        t->len += 100;
    }

    t->data[t->off++] = c;

    return 0;
}

results in the warning:

$ clang --analyze -c -O releak.c
releak.c:14:4: warning: Memory is never released; potential leak
                        return -1;
                        ^
1 warning generated.

even though its the caller's responsibility to handle the error and release
the structure.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list