Skip to content

Fix atom leak in JS_NewSymbol#1452

Open
engsr6982 wants to merge 1 commit intoquickjs-ng:masterfrom
engsr6982:master
Open

Fix atom leak in JS_NewSymbol#1452
engsr6982 wants to merge 1 commit intoquickjs-ng:masterfrom
engsr6982:master

Conversation

@engsr6982
Copy link
Copy Markdown
Contributor

This leak was introduced in commit 4a66289 when the public JS_NewSymbol API was first added. The function calls JS_NewAtom to create an atom from the description string, but never calls JS_FreeAtom after passing it to JS_NewSymbolFromAtom. This results in the atom's reference count never reaching zero, leaking memory for every symbol created via this C API.

@engsr6982
Copy link
Copy Markdown
Contributor Author

engsr6982 commented Apr 14, 2026

Actions don't look good, I'll take another look.

@engsr6982
Copy link
Copy Markdown
Contributor Author

I added JS_SetDumpFlags(rt, JS_DUMP_LEAKS | JS_DUMP_ATOM_LEAKS); to the new_symbol test case in api-test.c. The test output shows that there is indeed an atom leak here.

However, I'm not sure why adding JS_FreeAtom(ctx, atom); causes a segfault instead. Is this behavior by design, or is there something I'm missing about the atom lifecycle in JS_NewSymbol?

image

@saghul
Copy link
Copy Markdown
Contributor

saghul commented Apr 14, 2026

You are freeing the atom before you use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants