[llvm-bugs] [Bug 25882] New: Analyzer misses memory leak if memory is allocated as default initialization of class member
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Dec 18 06:40:19 PST 2015
https://llvm.org/bugs/show_bug.cgi?id=25882
Bug ID: 25882
Summary: Analyzer misses memory leak if memory is allocated as
default initialization of class member
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Static Analyzer
Assignee: kremenek at apple.com
Reporter: t at sharklasers.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 15483
--> https://llvm.org/bugs/attachment.cgi?id=15483&action=edit
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.
--
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/20151218/ddfcc1e6/attachment.html>
More information about the llvm-bugs
mailing list