summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2023-09-12 14:07:19 -0400
committerPeter LaFosse <peter@vector35.com>2023-09-12 17:40:03 -0400
commitcb8fdff6f09200f0e8629df146a50c12efbac129 (patch)
treea51053dbf79645137d8dcfc679a73f80cb56cb37
parente8298251d7d85778437b5587a53e7e00b30b16d9 (diff)
Fix type leak any time a plugin data renderer is called
-rw-r--r--datarenderer.cpp24
1 files changed, 21 insertions, 3 deletions
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<pair<Type*, size_t>> 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<pair<Type*, size_t>> 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;
}