Commit Graph
6 Commits
Author SHA1 Message Date
dualfroz fc2b1d3835 fix: drop the allocator release for slice paths in update 2026-09-13 23:22:06 +02:00
upstream 096ffac211 Upstream itchyny/gojq state of the touched files before 326d9db5da 2026-09-13 23:22:06 +02:00
dualfrozandClaude Opus 5 1b0e1db888 fix: release the allocator when an updated value escapes to a query
The allocator of _modify tracks the values it created so that a later
update can modify them in place instead of copying them. When a target
path is a proper prefix of an earlier one, getpath hands such a value to
the update function, which may store it in more than one place; updating
through one of those places then changes all of them.

    $ gojq -cn '{"a":{"b":1}} | (.a.b, .a, .a.p.z) |= {p: ., q: .}'

.a.p and .a.q hold separate values in jq, so only .a.p gains the "z" key,
while gojq adds it to both. Release the allocator whenever a value it
created leaves the update, so that the values are copied on update from
then on. The same applies to an object used as a path element, which
stays reachable through the path after the update.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 08:20:57 +02:00
upstream b18851b748 Upstream itchyny/gojq state of the touched files before f68bda411a 2026-09-04 08:20:57 +02:00
dualfroz a7ed5ccbe9 fix: release the allocator when an updated value escapes to a query
The allocator of _modify tracks the values it created so that a later
update can modify them in place instead of copying them. When a target
path is a proper prefix of an earlier one, getpath hands such a value to
the update function, which may store it in more than one place; updating
through one of those places then changes all of them.

    $ gojq -cn '{"a":{"b":1}} | (.a.b, .a, .a.p.z) |= {p: ., q: .}'

.a.p and .a.q hold separate values in jq, so only .a.p gains the "z" key,
while gojq adds it to both. Release the allocator whenever a value it
created leaves the update, so that the values are copied on update from
then on. The same applies to an object used as a path element, which
stays reachable through the path after the update.
2026-09-13 17:03:33 +02:00
upstream f2996ce6e7 Upstream itchyny/gojq state of the touched files before 3194dce466 2026-09-04 08:20:57 +02:00