[llvm-bugs] [Bug 46314] New: Spurious warning "Use of memory after it is freed" after realloc

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jun 13 11:58:34 PDT 2020


            Bug ID: 46314
           Summary: Spurious warning "Use of memory after it is freed"
                    after realloc
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: dank at kegel.com
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

The code

a (int x)
  char in, re;
  unsigned next;
  in = malloc (1);
  next = 0;
  if (x)
     next = 2;
  re = realloc (in, next);
  return re == ((void *) 0) ? in : re;

causes --analyze to emit

bad.c:10:3: warning: Use of memory after it is freed [unix.Malloc]
  return re == ((void *) 0) ? in : re;

which appears to be a false positive.

Tested with 
Ubuntu clang version
but also affects 
clang version 11.0.0-++20200523063809+304b0ed4039-1~exp1~20200523164413.1701

Reduced from https://github.com/zlib-ng/zlib-ng/issues/593

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/20200613/3f2793c0/attachment.html>

More information about the llvm-bugs mailing list