You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
memory leak: Set.prototype.union / symmetricDifference double-incref object elements (redundant js_dup into map_add_record) #1565
Set.prototype.union (js_set_union, quickjs.c:53898) and Set.prototype.symmetricDifference (js_set_symmetricDifference, quickjs.c:53815) leak every object element of the receiver set. Both copy the receiver's records into an intermediate set with map_add_record(ctx, t, js_dup(mr->key)), but map_add_recordalready dups the key internally (mr->key = js_dup(key)), so the extra js_dup over‑increments the key's refcount by one. Primitive keys (numbers, etc.) are not reference‑counted so nothing is observable, but object keys are leaked — they are never freed.
newSet([{}]).union(newSet([9]));// leaks the {} elementnewSet([{}]).symmetricDifference(newSet([9]));// same
Deterministic (20/20). new Set([1]).union(...) (a primitive element) does not leak, which is the tell: only reference‑counted (object) elements are affected.
The over‑incremented object survives to runtime teardown. In a long‑running process each union/symmetricDifference over a set that contains objects leaks those objects — an unbounded memory leak.
Root cause
map_add_record (quickjs.c:52742) takes a borrowed key and dups it into the record:
Activity
saghul commentedon Jul 14, 2026
Thanks for your he report! Would you like to send a PR?
saghul commentedon Jul 14, 2026
Fix in #1567
xmzyshypnc commentedon Jul 14, 2026
Sorry I just saw your response. Thanks for your quick fix!
Fix memory leak in Set.prototype set operations
Fix memory leak in Set.prototype set operations