Visitar URL original
Fix memory leaks by julianmesa-gitkraken · Pull Request #1944 · nodegit/nodegit · GitHub
Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix leak
 We need to free duplicated memory we are responsible for that we obtained from libgit2 because nodegit duplicates it again when calling the wrapper
  • Loading branch information
julianmesa-gitkraken committed Oct 21, 2022
commit 6c4e32d684ed3fad8f9d437868de884f94d5217f
13 changes: 13 additions & 0 deletions generate/templates/partials/async_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,19 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
Nan::Set(result, Nan::New("{{ _return.returnNameOrName }}").ToLocalChecked(), v8ConversionSlot);
{%endif%}
{%endeach%}

{%each args|argsInfo as arg %}
{%if not arg.shouldAlloc %}
{%if arg.ownedByThis|and arg.dupFunction|and arg.freeFunctionName|and arg.isReturn|and arg.selfFreeing %}
// We need to free duplicated memory we are responsible for that we obtained from libgit2 because
// nodegit duplicates it again when calling the wrapper
if(baton->{{ arg.name }} != NULL) {
{{ arg.freeFunctionName }}(baton->{{ arg.name }});
}
{%endif%}
{%endif%}
{%endeach%}

{%if .|returnsCount == 1 %}
v8::Local<v8::Value> result = v8ConversionSlot;
{%endif%}
Expand Down