Skip to content

fix: reference leaks in the store extension (ext_store.c) - #234

Merged
InauguralPhysicist merged 1 commit into
mainfrom
fix/json-parse-leak
Jun 18, 2026
Merged

fix: reference leaks in the store extension (ext_store.c)#234
InauguralPhysicist merged 1 commit into
mainfrom
fix/json-parse-leak

Conversation

@InauguralPhysicist

Copy link
Copy Markdown
Collaborator

Three leak sources in the store/JSON extension, surfaced by the ASan leaker enumeration (test_store, test_handle_forge, test_lab):

  1. JSON parser. store_json_parse_object allocated a key Value purely to read key->data.str then never freed it (one VAL_STR leaked per object key — test_lab's bulk), and both parsers dict_set/list_append'd values (which incref) without releasing the parser's own ref. Now use dict_set_owned/list_append_owned + free the key carrier; error paths free the partial dict/list/key.

  2. Catalog lifecycle. store_close and the open error paths free(store)'d without val_decref(store->catalog), leaking the parsed catalog dict per store. Added a store_free helper (decref catalog, then free); all free(store) sites route through it. The catalog-rewrite path drops the old catalog before replacing.

  3. Write path. store_put incref'd a new collection's col_info into the catalog without adopting (dict_set -> dict_set_owned); store_update built arg-lists for internal store_delete/store_put C calls and ignored their returns, freeing none. All balanced.

Clears test_store + test_handle_forge under ASan; harness leak tally 10->8 (these two are the regression guards). test_lab still leaks — a separate lib/lab.eigs store-not-closed lifecycle bug, follow-up.

Release 1941/1941, ASan 1941/1941 (tally 8).

What does this PR do?

Checklist

  • make test passes locally
  • New builtins have signature comments and docs in docs/BUILTINS.md
  • New library functions follow conventions in docs/STDLIB.md
  • New examples have a comment header explaining what they demonstrate
  • CHANGELOG.md updated (if user-facing change)

Three leak sources in the store/JSON extension, surfaced by the ASan
leaker enumeration (test_store, test_handle_forge, test_lab):

1. JSON parser. store_json_parse_object allocated a `key` Value purely to
   read key->data.str then never freed it (one VAL_STR leaked per object
   key — test_lab's bulk), and both parsers dict_set/list_append'd values
   (which incref) without releasing the parser's own ref. Now use
   dict_set_owned/list_append_owned + free the key carrier; error paths
   free the partial dict/list/key.

2. Catalog lifecycle. store_close and the open error paths free(store)'d
   without val_decref(store->catalog), leaking the parsed catalog dict per
   store. Added a store_free helper (decref catalog, then free); all
   free(store) sites route through it. The catalog-rewrite path drops the
   old catalog before replacing.

3. Write path. store_put incref'd a new collection's col_info into the
   catalog without adopting (dict_set -> dict_set_owned); store_update
   built arg-lists for internal store_delete/store_put C calls and ignored
   their returns, freeing none. All balanced.

Clears test_store + test_handle_forge under ASan; harness leak tally 10->8
(these two are the regression guards). test_lab still leaks — a separate
lib/lab.eigs store-not-closed lifecycle bug, follow-up.

Release 1941/1941, ASan 1941/1941 (tally 8).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@InauguralPhysicist
InauguralPhysicist merged commit 1ae915a into main Jun 18, 2026
11 checks passed
@InauguralPhysicist
InauguralPhysicist deleted the fix/json-parse-leak branch June 18, 2026 20:43
InauguralPhysicist added a commit that referenced this pull request Jun 19, 2026
… recovery

Patch release on top of 0.16.0. Highlights:
- Remote HTTP DoS fixed (Content-Length SEGV; missing _GNU_SOURCE → 64-bit
  pointer truncation) and the implicit-declaration class hard-errored in the
  build (#239/#240).
- ASan leak tally driven 10 → 4 (spawn-thread floor) across the runtime,
  HTTP code routes, container builtins, and the store extension
  (#234/#235/#236/#233).
- OSR/JIT coverage for observed-assign loops recovered: #211's conservative
  scanner bail replaced by the real fix — reset the OP_POP last_imm peephole
  at forward-jump targets — so those loops OSR-compile again (~34%, #231).
- Docs: clarified the implicit-`n` parameter shadows an outer `n` (#241,
  not a bug).

Also repairs CHANGELOG drift: commit 8fe0731 had accidentally deleted the
`## [0.16.0] — 2026-06-18` header, folding released 0.16.0 content back into
[Unreleased]. The header is restored (with its summary), the windowed-predicate
+ #212/#213/#214 entries are reattributed to 0.16.0 (their code shipped in the
v0.16.0 tag), and everything post-tag is grouped under the new [0.16.1].

VERSION 0.16.0 → 0.16.1. Release 1943/1943; ASan 1943/1943, leak tally 4.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant