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: dcough...@apple.com
Reporter: jakob.le...@gmail.com
CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs