Visitar URL original
Fix memory leaks · nodegit/nodegit@4fcce07 · GitHub
Skip to content

Commit 4fcce07

Browse files
Fix memory leaks
1 parent 1c304e5 commit 4fcce07

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

‎generate/templates/partials/async_function.cc‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,33 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::Execute() {
178178
baton->result = result;
179179

180180
{%endif%}
181+
182+
{%each args|argsInfo as arg %}
183+
{%if not arg.isSelf %}
184+
{%if not arg.payloadFor %}
185+
{%if not arg.isCallbackFunction %}
186+
{%if not arg.isStructType %}
187+
{%if not arg.payloadFor %}
188+
{%if not arg.isStructType %}
189+
{%if not arg.isReturn %}
190+
{%if not arg.isPayload %}
191+
{%if arg.name %}
192+
{%if arg.cppClassName == 'String'%}
193+
free((void*)baton->{{ arg.name }});
194+
{%endif%}
195+
{%if arg.cppClassName == 'Wrapper'%}
196+
free((void*)baton->{{ arg.name }});
197+
{%endif%}
198+
{%endif%}
199+
{%endif%}
200+
{%endif%}
201+
{%endif%}
202+
{%endif%}
203+
{%endif%}
204+
{%endif%}
205+
{%endif%}
206+
{%endif%}
207+
{%endeach%}
181208
}
182209

183210
void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleErrorCallback() {
@@ -201,6 +228,14 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleErrorCallback() {
201228
{%each args|argsInfo as arg %}
202229
{%if arg.shouldAlloc %}
203230
{%if not arg.isCppClassStringOrArray %}
231+
{%if arg.cppClassName == "GitBuf" %}
232+
{%else%}
233+
{%if arg | isOid %}
234+
{%else%}
235+
// new free
236+
free((void*)baton->{{ arg.name }});
237+
{%endif%}
238+
{%endif%}
204239
{%elsif arg | isOid %}
205240
if (baton->{{ arg.name}}NeedsFree) {
206241
baton->{{ arg.name}}NeedsFree = false;
@@ -346,6 +381,13 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
346381
{%each args|argsInfo as arg %}
347382
{%if arg.shouldAlloc %}
348383
{%if not arg.isCppClassStringOrArray %}
384+
{%if arg.cppClassName == "GitBuf" %}
385+
{%else%}
386+
{%if arg | isOid %}
387+
{%else%}
388+
free((void*)baton->{{ arg.name }});
389+
{%endif%}
390+
{%endif%}
349391
{%elsif arg | isOid %}
350392
if (baton->{{ arg.name}}NeedsFree) {
351393
baton->{{ arg.name}}NeedsFree = false;

‎generate/templates/partials/sync_function.cc‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,16 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
9595

9696
{%each args|argsInfo as arg %}
9797
{%if arg | isOid %}
98-
if (info[{{ arg.jsArg }}]->IsString()) {
99-
free((void *)from_{{ arg.name }});
100-
}
98+
if (info[{{ arg.jsArg }}]->IsString()) {
99+
free((void *)from_{{ arg.name }});
100+
}
101+
{%else%}
102+
{%if arg.cppClassName == 'String'%}
103+
free((void *)from_{{ arg.name }});
104+
{%endif%}
105+
{%if arg.cppClassName == 'Wrapper'%}
106+
free((void *)from_{{ arg.name }});
107+
{%endif%}
101108
{%endif%}
102109
{%endeach%}
103110

0 commit comments

Comments
 (0)