From cb8fdff6f09200f0e8629df146a50c12efbac129 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Tue, 12 Sep 2023 14:07:19 -0400 Subject: Fix type leak any time a plugin data renderer is called --- datarenderer.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'datarenderer.cpp') diff --git a/datarenderer.cpp b/datarenderer.cpp index 8d1b16b4..40c64d66 100644 --- a/datarenderer.cpp +++ b/datarenderer.cpp @@ -45,9 +45,19 @@ bool DataRenderer::IsValidForDataCallback( vector> context; context.reserve(ctxCount); for (size_t i = 0; i < ctxCount; i++) - context.push_back({new Type(BNNewTypeReference(typeCtx[i].type)), typeCtx[i].offset}); + { + // To keep API compatibility we have to manually do the refcounting here + Type* contextType = new Type(BNNewTypeReference(typeCtx[i].type)); + contextType->AddRef(); + context.push_back({contextType, typeCtx[i].offset}); + } + + bool result = renderer->IsValidForData(viewObj, addr, typeObj, context); + + for (size_t i = 0; i < ctxCount; i++) + context[i].first->Release(); - return renderer->IsValidForData(viewObj, addr, typeObj, context); + return result; } @@ -63,7 +73,12 @@ BNDisassemblyTextLine* DataRenderer::GetLinesForDataCallback(void* ctxt, BNBinar vector> context; context.reserve(ctxCount); for (size_t i = 0; i < ctxCount; i++) - context.push_back({new Type(BNNewTypeReference(typeCtx[i].type)), typeCtx[i].offset}); + { + // To keep API compatibility we have to manually do the refcounting here + Type* contextType = new Type(BNNewTypeReference(typeCtx[i].type)); + contextType->AddRef(); + context.push_back({contextType, typeCtx[i].offset}); + } auto lines = renderer->GetLinesForData(viewObj, addr, typeObj, prefixes, width, context); *count = lines.size(); BNDisassemblyTextLine* buf = new BNDisassemblyTextLine[lines.size()]; @@ -77,6 +92,9 @@ BNDisassemblyTextLine* DataRenderer::GetLinesForDataCallback(void* ctxt, BNBinar buf[i].count = line.tokens.size(); buf[i].tags = Tag::CreateTagList(line.tags, &(buf[i].tagCount)); } + + for (size_t i = 0; i < ctxCount; i++) + context[i].first->Release(); return buf; } -- cgit v1.3.1