Mesa (master): gallivm: fix 2 leaks in disassembly code
Roland Scheidegger
sroland at kemper.freedesktop.org
Thu May 1 14:13:48 UTC 2014
Module: Mesa
Branch: master
Commit: 64d6460a56119c2da726d7de426dc8ac33e7f8bc
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=64d6460a56119c2da726d7de426dc8ac33e7f8bc
Author: Roland Scheidegger <sroland at vmware.com>
Date: Thu May 1 00:31:47 2014 +0200
gallivm: fix 2 leaks in disassembly code
don't leak the MCSubtargetInfo (not really big, was already fixed with
llvm master) and TargetMachine (big). While this is only used for debugging
the leak is large enough to get you into trouble in some cases.
Tested with llvm 3.1 and master.
Before (llvm 3.1), GALLIVM_DEBUG=asm glxgears:
==14152== LEAK SUMMARY:
==14152== definitely lost: 105,228 bytes in 20 blocks
==14152== indirectly lost: 347,252 bytes in 261 blocks
==14152== possibly lost: 866,625 bytes in 1,453 blocks
==14152== still reachable: 7,344,677 bytes in 6,494 blocks
==14152== suppressed: 0 bytes in 0 blocks
After:
==13799== LEAK SUMMARY:
==13799== definitely lost: 3,108 bytes in 6 blocks
==13799== indirectly lost: 0 bytes in 0 blocks
==13799== possibly lost: 804,143 bytes in 1,429 blocks
==13799== still reachable: 7,314,267 bytes in 6,473 blocks
==13799== suppressed: 0 bytes in 0 blocks
Reviewed-by: Brian Paul <brianp at vmware.com>
---
src/gallium/auxiliary/gallivm/lp_bld_debug.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
index 541cf9e..7e43b51 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
@@ -36,6 +36,7 @@
#if HAVE_LLVM >= 0x0300
#include <llvm/Support/TargetRegistry.h>
+#include <llvm/MC/MCSubtargetInfo.h>
#else /* HAVE_LLVM < 0x0300 */
#include <llvm/Target/TargetRegistry.h>
#endif /* HAVE_LLVM < 0x0300 */
@@ -254,7 +255,7 @@ disassemble(const void* func, llvm::raw_ostream & Out)
OwningPtr<MCContext> MCCtx(new MCContext(AsmInfo.get(), MRI.get(), 0));
OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler(*STI, *MCCtx));
#elif HAVE_LLVM >= 0x0300
- const MCSubtargetInfo *STI = T->createMCSubtargetInfo(Triple, sys::getHostCPUName(), "");
+ OwningPtr<const MCSubtargetInfo> STI(T->createMCSubtargetInfo(Triple, sys::getHostCPUName(), ""));
OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler(*STI));
#else
OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler());
@@ -294,11 +295,11 @@ disassemble(const void* func, llvm::raw_ostream & Out)
#if defined(DEBUG) || defined(PROFILE)
options.NoFramePointerElim = true;
#endif
- TargetMachine *TM = T->createTargetMachine(Triple, sys::getHostCPUName(), "", options);
+ OwningPtr<TargetMachine> TM(T->createTargetMachine(Triple, sys::getHostCPUName(), "", options));
#elif HAVE_LLVM == 0x0300
- TargetMachine *TM = T->createTargetMachine(Triple, sys::getHostCPUName(), "");
+ OwningPtr<TargetMachine> TM(T->createTargetMachine(Triple, sys::getHostCPUName(), ""));
#else
- TargetMachine *TM = T->createTargetMachine(Triple, "");
+ OwningPtr<TargetMachine> TM(T->createTargetMachine(Triple, ""));
#endif
const TargetInstrInfo *TII = TM->getInstrInfo();
More information about the mesa-commit
mailing list