Skip to content

Commit

Permalink
Copy buffer for Application#icon and Application#nacp
Browse files Browse the repository at this point in the history
This avoids the `app` getting garbage collected and the ArrayBuffer
pointing to garbage data.
  • Loading branch information
TooTallNate committed Mar 10, 2024
1 parent aa25e32 commit eb1d82a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-windows-add.md
@@ -0,0 +1,5 @@
---
"nxjs-runtime": patch
---

Copy buffer for `Application#icon` and `Application#nacp`
4 changes: 2 additions & 2 deletions source/ns.c
Expand Up @@ -112,7 +112,7 @@ static JSValue nx_ns_app_nacp(JSContext *ctx, JSValueConst this_val, int argc, J
{
return JS_EXCEPTION;
}
return JS_NewArrayBuffer(ctx, (uint8_t *)&app->data.nacp, sizeof(app->data.nacp), NULL, NULL, false);
return JS_NewArrayBufferCopy(ctx, (uint8_t *)&app->data.nacp, sizeof(app->data.nacp));
}

static JSValue nx_ns_app_icon(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
Expand All @@ -126,7 +126,7 @@ static JSValue nx_ns_app_icon(JSContext *ctx, JSValueConst this_val, int argc, J
{
return JS_UNDEFINED;
}
return JS_NewArrayBuffer(ctx, (uint8_t *)&app->data.icon, app->icon_size, NULL, NULL, false);
return JS_NewArrayBufferCopy(ctx, (uint8_t *)&app->data.icon, app->icon_size);
}

static JSValue nx_ns_app_name(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
Expand Down

0 comments on commit eb1d82a

Please sign in to comment.