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: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to