diff options
| author | Rusty Wagner <rusty.wagner@gmail.com> | 2023-09-12 14:07:19 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2023-09-12 17:40:03 -0400 |
| commit | cb8fdff6f09200f0e8629df146a50c12efbac129 (patch) | |
| tree | a51053dbf79645137d8dcfc679a73f80cb56cb37 /datarenderer.cpp | |
| parent | e8298251d7d85778437b5587a53e7e00b30b16d9 (diff) | |
Fix type leak any time a plugin data renderer is called
Diffstat (limited to 'datarenderer.cpp')
| -rw-r--r-- | datarenderer.cpp | 24 |
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; } |
