Skip to content
Merged
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
add yet more fixes from Julian
  • Loading branch information
zawata committed Nov 26, 2025
commit 231f4721dc97775c1a22ba267ced7e9885bcdf33
7 changes: 4 additions & 3 deletions generate/templates/partials/async_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,21 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
{% if arg.cppClassName == 'Array' %}
{
v8::Local<v8::Array> tempArray = v8::Local<v8::Array>::Cast(info[{{ arg.jsArg }}]);
baton->{{ arg.name }} = new {{ arg.cType|unPointer }}[tempArray->Length()];
baton->{{ arg.name }} = ({{ arg.cType|unPointer }}*)malloc(sizeof({{ arg.cType|unPointer }}) * tempArray->Length());
for (uint32_t i = 0; i < tempArray->Length(); ++i) {
auto conversionResult = Configurable{{ arg.arrayElementCppClassName }}::fromJavascript(
nodegitContext,
Nan::Get(tempArray, i).ToLocalChecked()
);

if (!conversionResult.result) {
delete[] baton->{{ arg.name }};
// TODO free previously allocated memory
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still need to be handled?

Copy link
Copy Markdown
Contributor Author

@zawata zawata Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julianmesa-gitkraken this comment came from you.

Copy link
Copy Markdown
Contributor

@julianmesa-gitkraken julianmesa-gitkraken Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I will do it in another PR. I need to store all allocated memory in a map, then if I get an error reading javascript arguments we have to release all allocated memory, then throw the error.

free(baton->{{ arg.name }});
return Nan::ThrowError(Nan::New(conversionResult.error).ToLocalChecked());
}

auto convertedObject = conversionResult.result;
cleanupHandles["{{ arg.name }}"] = convertedObject;
cleanupHandles[std::string("{{ arg.name }}") + std::to_string(i)] = convertedObject;
baton->{{ arg.name }}[i] = *convertedObject->GetValue();
}
}
Expand Down