Skip to content

Commit

Permalink
Fixed the problem. We needed to allocate the array on the heap. Also …
Browse files Browse the repository at this point in the history
…make sur to free the array and the strings
  • Loading branch information
GustavoCaso committed Dec 23, 2021
1 parent 33f0e43 commit 7e6661c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ func valueStrings(ctx *Context, rtn C.RtnStrings) []string {
var result []string
for i := 0; i < len(slice); i++ {
s := slice[i]
defer C.free(unsafe.Pointer(s))
result = append(result, C.GoString(s))
}
defer C.free(unsafe.Pointer(rtn.strings))
return result
}

Expand Down
2 changes: 1 addition & 1 deletion v8go.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ RtnStrings ObjectGetPropertyNames(ValuePtr ptr) {
Local<Array> names = maybe_names.ToLocalChecked();

uint32_t length = names->Length();
const char* strings[length];
const char **strings = new const char*[length];

for (int i = 0; i < length; i++) {
Local<Value> name_from_array = names->Get(local_ctx, i).ToLocalChecked();
Expand Down

0 comments on commit 7e6661c

Please sign in to comment.