From 859a17a4b8d59b934e599f928f41613f30e2470c Mon Sep 17 00:00:00 2001 From: Stjepan Rajko Date: Mon, 25 Apr 2016 11:56:13 -0700 Subject: [PATCH] Fix memory leak on ignoreInit --- generate/templates/templates/struct_content.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/generate/templates/templates/struct_content.cc b/generate/templates/templates/struct_content.cc index 3bb619d92..bc620d582 100644 --- a/generate/templates/templates/struct_content.cc +++ b/generate/templates/templates/struct_content.cc @@ -32,14 +32,12 @@ using namespace std; {{ cppClassName }}::{{ cppClassName }}() : NodeGitWrapper<{{ cppClassName }}Traits>(NULL, true, v8::Local()) { {% if ignoreInit == true %} - // TODO: this looks like a memory leak to me - we are allocating wrappedValue - // then copying it below, but never freeing it - {{ cType }}* wrappedValue = new {{ cType }}; + this->raw = new {{ cType }}; {% else %} {{ cType }} wrappedValue = {{ cType|upper }}_INIT; - {% endif %} this->raw = ({{ cType }}*) malloc(sizeof({{ cType }})); memcpy(this->raw, &wrappedValue, sizeof({{ cType }})); + {% endif %} this->ConstructFields(); }