<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi,<br>
<br>
I've run Clang Static Analyzer checker
alpha.cplusplus.NewDeleteLeaks over LLVM codebase to detect
false-positives and at the same time eliminate memory leaks. The
majority of leaks were detected in lib/Target/* and lib/MC/*. In all
cases the similar trick was detected as a leak (example from lib<span
class="W"></span>/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp)
:<br>
<br>
<font face="Courier New, Courier, monospace">static MCStreamer
*createMCStreamer(const Target &T, StringRef TT,<br>
MCContext &Context,
MCAsmBackend &MAB,<br>
raw_ostream &OS,
MCCodeEmitter *Emitter,<br>
const MCSubtargetInfo
&STI, bool RelaxAll,<br>
bool NoExecStack) {<br>
MCStreamer *S =<br>
createELFStreamer(Context, MAB, OS, Emitter, RelaxAll,
NoExecStack);<br>
new SparcTargetELFStreamer(*S);<br>
<br>
1 Memory is allocated →<br>
<br>
return S;<br>
<br>
2 ← Potential memory leak<br>
}<br>
</font><br>
Have not got why is this SparcTargetELFStreamer created dynamically
and not assigned.<br>
Can anybody please explain is this a trick or a trouble?<br>
<br>
The similar pattern was detected in<br>
lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp<br>
lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp<br>
lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp <br>
lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp<br>
lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp<br>
lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp<br>
lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp<br>
lib/MC/MCELFStreamer.cpp<br>
lib/MC/WinCOFFStreamer.cpp<br>
lib/MC/MCMachOStreamer.cpp<br>
<br>
<pre class="moz-signature" cols="72">--
Anton</pre>
</body>
</html>