From d934d91dc49e87ca5da21b0cfa7e4420094240f1 Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Fri, 24 Dec 2021 00:07:32 +0100 Subject: [PATCH] Fixed the problem. We needed to allocate the array on the heap. Also make sur to free the array and the strings --- context.go | 2 ++ v8go.cc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index 0beb1a2e0..e444e5e15 100644 --- a/context.go +++ b/context.go @@ -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 } diff --git a/v8go.cc b/v8go.cc index b22cc7340..7d9cd4af4 100644 --- a/v8go.cc +++ b/v8go.cc @@ -1298,7 +1298,7 @@ RtnStrings ObjectGetPropertyNames(ValuePtr ptr) { Local 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 name_from_array = names->Get(local_ctx, i).ToLocalChecked();