<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Analyzer reports memory leak when returning vector of pointers from function in shared library"
href="https://bugs.llvm.org/show_bug.cgi?id=36259">36259</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Analyzer reports memory leak when returning vector of pointers from function in shared library
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>5.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Static Analyzer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>dcoughlin@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jakob.leben@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>