summaryrefslogtreecommitdiff
path: root/objectivec
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2025-07-08 10:30:26 -0700
committerMark Rowe <mark@vector35.com>2025-07-08 23:32:41 -0700
commit6cb671483fe02f0e9ab20bab189101d1cc8210a1 (patch)
tree9c588a50ec552bb3e3cf5b502e5f7e190834d1dd /objectivec
parentf628cc695c680469c441394511a72b3b3912dd7f (diff)
[MachO] Avoid leaking MachoObjCProcessor
This would leak if parsing of CFStrings was enabled while parsing of Objective-C metadata was disabled. It would also leak if exceptions were thrown or early returns were taken in the ~500 lines between where the object was allocated and it was deleted.
Diffstat (limited to 'objectivec')
-rw-r--r--objectivec/objc.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/objectivec/objc.cpp b/objectivec/objc.cpp
index 6316c11f..f0a6a8f3 100644
--- a/objectivec/objc.cpp
+++ b/objectivec/objc.cpp
@@ -1713,7 +1713,7 @@ void ObjCProcessor::ProcessCFStrings()
void ObjCProcessor::ProcessNSConstantArrays()
{
- m_symbolQueue = new SymbolQueue();
+ auto guard = ScopedSymbolQueue::Make();
uint64_t ptrSize = m_data->GetAddressSize();
auto idType = Type::NamedType(m_data, m_typeNames.id);
@@ -1742,16 +1742,16 @@ void ObjCProcessor::ProcessNSConstantArrays()
fmt::format("nsarray_{:x}", i), i, true);
}
auto id = m_data->BeginUndoActions();
- m_symbolQueue->Process();
+ ScopedSymbolQueue::Get().Process();
m_data->EndBulkModifySymbols();
m_data->ForgetUndoActions(id);
}
- delete m_symbolQueue;
+
}
void ObjCProcessor::ProcessNSConstantDictionaries()
{
- m_symbolQueue = new SymbolQueue();
+ auto guard = ScopedSymbolQueue::Make();
uint64_t ptrSize = m_data->GetAddressSize();
auto idType = Type::NamedType(m_data, m_typeNames.id);
@@ -1786,16 +1786,15 @@ void ObjCProcessor::ProcessNSConstantDictionaries()
fmt::format("nsdict_{:x}", i), i, true);
}
auto id = m_data->BeginUndoActions();
- m_symbolQueue->Process();
+ ScopedSymbolQueue::Get().Process();
m_data->EndBulkModifySymbols();
m_data->ForgetUndoActions(id);
}
- delete m_symbolQueue;
}
void ObjCProcessor::ProcessNSConstantIntegerNumbers()
{
- m_symbolQueue = new SymbolQueue();
+ auto guard = ScopedSymbolQueue::Make();
uint64_t ptrSize = m_data->GetAddressSize();
StructureBuilder nsConstantIntegerNumberBuilder;
@@ -1844,11 +1843,10 @@ void ObjCProcessor::ProcessNSConstantIntegerNumbers()
}
}
auto id = m_data->BeginUndoActions();
- m_symbolQueue->Process();
+ ScopedSymbolQueue::Get().Process();
m_data->EndBulkModifySymbols();
m_data->ForgetUndoActions(id);
}
- delete m_symbolQueue;
}
void ObjCProcessor::ProcessNSConstantFloatingPointNumbers()
@@ -1893,7 +1891,7 @@ void ObjCProcessor::ProcessNSConstantFloatingPointNumbers()
if (!numbers)
continue;
- m_symbolQueue = new SymbolQueue();
+ auto guard = ScopedSymbolQueue::Make();
auto start = numbers->GetStart();
auto end = numbers->GetEnd();
auto typeWidth = Type::NamedType(m_data, m_typeNames.nsConstantDoubleNumber)->GetWidth();
@@ -1935,16 +1933,15 @@ void ObjCProcessor::ProcessNSConstantFloatingPointNumbers()
DefineObjCSymbol(DataSymbol, Type::NamedType(m_data, *typeName), name, i, true);
}
auto id = m_data->BeginUndoActions();
- m_symbolQueue->Process();
+ ScopedSymbolQueue::Get().Process();
m_data->EndBulkModifySymbols();
m_data->ForgetUndoActions(id);
- delete m_symbolQueue;
}
}
void ObjCProcessor::ProcessNSConstantDatas()
{
- m_symbolQueue = new SymbolQueue();
+ auto guard = ScopedSymbolQueue::Make();
uint64_t ptrSize = m_data->GetAddressSize();
StructureBuilder nsConstantDataBuilder;
@@ -1972,11 +1969,10 @@ void ObjCProcessor::ProcessNSConstantDatas()
DataSymbol, Type::NamedType(m_data, m_typeNames.nsConstantData), fmt::format("nsdata_{:x}", i), i, true);
}
auto id = m_data->BeginUndoActions();
- m_symbolQueue->Process();
+ ScopedSymbolQueue::Get().Process();
m_data->EndBulkModifySymbols();
m_data->ForgetUndoActions(id);
}
- delete m_symbolQueue;
}
void ObjCProcessor::AddRelocatedPointer(uint64_t location, uint64_t rewrite)