[llvm-bugs] [Bug 36259] New: Analyzer reports memory leak when returning vector of pointers from function in shared library

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 6 17:21:51 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36259

            Bug ID: 36259
           Summary: Analyzer reports memory leak when returning vector of
                    pointers from function in shared library
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: jakob.leben at gmail.com
                CC: llvm-bugs at lists.llvm.org

The following example causes a potential memory leak report:

---- example-bad.cpp ----

#include <vector>

std::vector<int*> create_ints()
{
    return { new int };
}

-------------------------

$ scan-build-5.0 clang++-5.0 -shared example-bad.cpp -std=c++11 -fPIC
scan-build: Using '/usr/lib/llvm-5.0/bin/clang' for static analysis
example-bad.cpp:6:12: warning: Potential memory leak
    return { new int };
           ^~~~~~~~~~~


The following example doesn't cause the memory leak report though:

---- example-good.cpp ----

int * create_int()
{
    return new int;
}

-------------------------

$ scan-build-5.0 clang++-5.0 -shared example-good.cpp -std=c++11 -fPIC
...
scan-build: No bugs found.


I would like the first example to not cause the report, just like the second.
The allocated memory is supposed to be returned by the program linked to the
library.

-- 
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/20180207/801fd435/attachment-0001.html>


More information about the llvm-bugs mailing list