summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-10 18:38:33 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-10 18:38:33 +0100
commit11432f7a08fd0795df7617d1e01bf39a6706f24a (patch)
tree1344d481df4821ed7be34a71aff6a794e76656e0
parentc9c88166beaa21524ad7f31e1b15bee5d711b0c7 (diff)
Fix leak when slurping invalid text
-rw-r--r--jq.pyx3
-rw-r--r--tests/jq_tests.py11
2 files changed, 14 insertions, 0 deletions
diff --git a/jq.pyx b/jq.pyx
index 6c21b57..7d2875b 100644
--- a/jq.pyx
+++ b/jq.pyx
@@ -433,6 +433,9 @@ cdef class _ResultIterator(object):
except StopIteration:
self._slurp = False
break
+ except:
+ jv_free(value)
+ raise
else:
value = self._parse_next_input()
diff --git a/tests/jq_tests.py b/tests/jq_tests.py
index 69eccb2..1a891e6 100644
--- a/tests/jq_tests.py
+++ b/tests/jq_tests.py
@@ -129,6 +129,17 @@ def test_can_slurp_and_produce_multiple_output_values():
assert_equal([1, 2, 3], result)
+def test_slurping_invalid_input_text_raises_error():
+ program = jq.compile(".")
+
+ try:
+ program.input_text("!!", slurp=True).all()
+ assert False, "Expected error"
+ except ValueError as error:
+ expected_error_str = "parse error: Invalid numeric literal at EOF at line 1, column 2"
+ assert_equal(str(error), expected_error_str)
+
+
def test_when_text_method_is_used_on_result_then_output_is_serialised_to_json_string():
assert_equal(
'"42"',