Skip to content

Commit

Permalink
Fix string memory leak in Switch.writeFileSync()
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Oct 6, 2023
1 parent cf578d8 commit aa87ace
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-paws-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nxjs-runtime': patch
---

Fix string memory leak in `Switch.writeFileSync()`
3 changes: 1 addition & 2 deletions source/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ JSValue nx_write_file_sync(JSContext *ctx, JSValueConst this_val, int argc, JSVa
JS_FreeCString(ctx, filename);
return JS_EXCEPTION;
}
JS_FreeCString(ctx, filename);

size_t size;
uint8_t *buffer = JS_GetArrayBuffer(ctx, &size, argv[1]);
if (buffer == NULL)
{
JS_FreeCString(ctx, filename);
fclose(file);
JS_ThrowOutOfMemory(ctx);
return JS_EXCEPTION;
Expand All @@ -216,7 +216,6 @@ JSValue nx_write_file_sync(JSContext *ctx, JSValueConst this_val, int argc, JSVa

if (result != size)
{
JS_FreeCString(ctx, filename);
JS_ThrowTypeError(ctx, "Failed to write entire file. Got %lu, expected %lu", result, result);
return JS_EXCEPTION;
}
Expand Down

0 comments on commit aa87ace

Please sign in to comment.