Skip to content

Commit 3ffe4db

Browse files
Free baton on error processing javascript arguments
We only free baton, but we should try to free all previously allocated memory.
1 parent 07a4593 commit 3ffe4db

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

generate/templates/partials/async_function.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
6464
);
6565

6666
if (!conversionResult.result) {
67-
delete[] baton->{{ arg.name }};
67+
// TODO free previously allocated memory
68+
free(baton->{{ arg.name }});
69+
delete baton;
6870
return Nan::ThrowError(Nan::New(conversionResult.error).ToLocalChecked());
6971
}
7072

@@ -77,6 +79,7 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
7779
{
7880
auto conversionResult = Configurable{{ arg.cppClassName }}::fromJavascript(nodegitContext, info[{{ arg.jsArg }}]);
7981
if (!conversionResult.result) {
82+
delete baton;
8083
return Nan::ThrowError(Nan::New(conversionResult.error).ToLocalChecked());
8184
}
8285

generate/templates/partials/convert_from_v8.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
Nan::Utf8String oidString(Nan::To<v8::String>(arrayVal).ToLocalChecked());
6161
string str = string(*oidString);
6262
if (git_oid_fromstr(&from_{{ name }}[i], str.c_str()) != GIT_OK) {
63+
delete baton;
6364
if (git_error_last()) {
6465
return Nan::ThrowError(git_error_last()->message);
6566
} else {
@@ -93,6 +94,7 @@
9394
string str = string(*oidString);
9495
if (git_oid_fromstr(oidOut, str.c_str()) != GIT_OK) {
9596
free(oidOut);
97+
delete baton;
9698

9799
if (git_error_last()) {
98100
return Nan::ThrowError(git_error_last()->message);

0 commit comments

Comments
 (0)