Skip to content

Commit a24d5f8

Browse files
Fix memory leaks
1 parent 1c304e5 commit a24d5f8

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

generate/templates/partials/async_function.cc

Lines changed: 45 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,17 @@ 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+
if (baton->{{ arg.name}}NeedsFree) {
235+
baton->{{ arg.name}}NeedsFree = false;
236+
free((void*)baton->{{ arg.name }});
237+
}
238+
{%else%}
239+
free((void*)baton->{{ arg.name }});
240+
{%endif%}
241+
{%endif%}
204242
{%elsif arg | isOid %}
205243
if (baton->{{ arg.name}}NeedsFree) {
206244
baton->{{ arg.name}}NeedsFree = false;
@@ -346,6 +384,13 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
346384
{%each args|argsInfo as arg %}
347385
{%if arg.shouldAlloc %}
348386
{%if not arg.isCppClassStringOrArray %}
387+
{%if arg.cppClassName == "GitBuf" %}
388+
{%else%}
389+
{%if arg | isOid %}
390+
{%else%}
391+
free((void*)baton->{{ arg.name }});
392+
{%endif%}
393+
{%endif%}
349394
{%elsif arg | isOid %}
350395
if (baton->{{ arg.name}}NeedsFree) {
351396
baton->{{ arg.name}}NeedsFree = false;

generate/templates/partials/sync_function.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,18 @@ 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 not arg.isReturn %}
103+
{%if arg.cppClassName == 'String'%}
104+
free((void *)from_{{ arg.name }});
105+
{%endif%}
106+
{%if arg.cppClassName == 'Wrapper'%}
107+
free((void *)from_{{ arg.name }});
108+
{%endif%}
109+
{%endif%}
101110
{%endif%}
102111
{%endeach%}
103112

0 commit comments

Comments
 (0)