From 6d3ea79f6981d1961a512bd38eb80e71b6a52bea Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Tue, 4 Dec 2012 21:08:40 -0500 Subject: [PATCH] Fix memory corruption issue. - Since BasicTargetInterface is a BReferenceable, we must not create it on the stack, else it will be destroyed while others still have references to it. Fixes various random crashes, though most frequently observable when typecasting with more complex types. --- .../debugger/debug_info/DwarfImageDebugInfo.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp index 2e29311615..3f570c64e3 100644 --- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp @@ -417,8 +417,15 @@ DwarfImageDebugInfo::GetType(GlobalTypeCache* cache, BReference fromDwarfMapReference(fromDwarfMap, true); // create the target interface - BasicTargetInterface inputInterface(registers, registerCount, fromDwarfMap, - fArchitecture, fTeamMemory); + BasicTargetInterface *inputInterface + = new(std::nothrow) BasicTargetInterface(registers, registerCount, + fromDwarfMap, fArchitecture, fTeamMemory); + + if (inputInterface == NULL) + return B_NO_MEMORY; + + BReference inputInterfaceReference(inputInterface, + true); // iterate through all compilation units for (int32 i = 0; CompilationUnit* unit = fFile->CompilationUnitAt(i); @@ -458,7 +465,7 @@ DwarfImageDebugInfo::GetType(GlobalTypeCache* cache, if (typeContext == NULL) { typeContext = new(std::nothrow) DwarfTypeContext(fArchitecture, fImageInfo.ImageID(), fFile, - unit, NULL, 0, 0, fRelocationDelta, &inputInterface, + unit, NULL, 0, 0, fRelocationDelta, inputInterface, fromDwarfMap); if (typeContext == NULL) return B_NO_MEMORY;