<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 - Memory leak checker doesn't report leak when constructor dereferences the argument"
href="https://bugs.llvm.org/show_bug.cgi?id=42573">42573</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Memory leak checker doesn't report leak when constructor dereferences the argument
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</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>hiraditya@msn.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Not sure why static analyzer doesn't report memory leak in the following case:
$ cat test.cpp
#include<memory>
#include<iostream>
struct A {
A(const std::shared_ptr<int> &s) {
std::cout << "constructor" << *s;
}
};
int main() {
auto l = std::make_shared<A>(nullptr);
int *p = new int;
int i = *p;
return i;
}
However, if we remove the dereference of `s` it works.
$ cat test-no-deref-s.cpp
#include<memory>
#include<iostream>
struct A {
A(const std::shared_ptr<int> &s) {
std::cout << "constructor"; // removed the deref of s
}
};
int main() {
auto l = std::make_shared<A>(nullptr);
int *p = new int;
int i = *p;
return i;
}
$ clang++ --analyze test-no-deref-s.cpp -std=c++14
test1.cpp:14:3: warning: Potential leak of memory pointed to by 'p'
int i = *p;
^~~~~
1 warning generated.</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>