<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 misses memory leak if memory is allocated as default initialization of class member"
href="https://llvm.org/bugs/show_bug.cgi?id=25882">25882</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Analyzer misses memory leak if memory is allocated as default initialization of class member
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>kremenek@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>t@sharklasers.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=15483" name="attach_15483" title="Code demonstrating the bug">attachment 15483</a> <a href="attachment.cgi?id=15483&action=edit" title="Code demonstrating the bug">[details]</a></span>
Code demonstrating the bug
The example code defines two classes. A allocates memory as default initializer
for a class member. B allocates the memory in the default constructor. Neither
of the classes deletes those allocations. The Address Sanitizer reports both
leaks.
$ g++ -std=c++14 -Wall -Wextra -fsanitize=address file1.cpp
$ ./a.out
=================================================================
==21229==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x7f59d54a2a4a in operator new[](unsigned long)
../../../../gcc-5.3.0/libsanitizer/asan/asan_new_delete.cc:62
#1 0x4009e5 in A::A() (a.out+0x4009e5)
#2 0x400904 in main (a.out+0x400904)
#3 0x7f59d47d2b04 in __libc_start_main (/lib64/libc.so.6+0x21b04)
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x7f59d54a2a4a in operator new[](unsigned long)
../../../../gcc-5.3.0/libsanitizer/asan/asan_new_delete.cc:62
#1 0x4009a1 in B::B() (a.out+0x4009a1)
#2 0x400910 in main (a.out+0x400910)
#3 0x7f59d47d2b04 in __libc_start_main (/lib64/libc.so.6+0x21b04)
SUMMARY: AddressSanitizer: 80 byte(s) leaked in 2 allocation(s).
The clang static analyzer detects only the leak of the allocation from B's
default constructor.
$ scan-build g++ -std=c++14 -Wall -Wextra -fsanitize=address file1.cpp
scan-build: Using 'local/tmp/clang/bin/clang' for static analysis
file1.cpp:18:1: warning: Potential leak of memory pointed to by 'b.p'
}
^
1 warning generated.
scan-build: 1 bug found.
scan-build: Run 'scan-view /tmp/scan-build-2015-12-18-153709-21294-1' to
examine bug reports.</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>