Closed Sameesunkaria closed 1 month ago
Hey, thanks. Possible to add a minimal reuse/reset regression test case to https://github.com/jqlang/jq/blob/master/src/jq_test.c that would be detected by valgrind?
Added a separate function for testing the jq_state
after calls to jq_start
. In theory these tests could be baked into the existing run_jq_tests
but currently it only ever calls jq_start
once for each program. To correctly validate the changes, we must run it against a "dirty" jq_state
that was reset by jq_start
.
Please let me know if you had something else in mind. :)
Please drop the change to gitignore file. Files generated not by the project should not be in per-project gitignore file.
Removed the commit with the changes to gitignore
jq_reset
callsjv_free
on theexit_code
and theerror_message
stored on the jq state. However, it doesn't replace the actual instance of those members. This means that subsequent calls tojq_reset
will calljv_free
again on those members, which in turn may callfree
on the same pointer multiple times. Freeing the same pointer multiple times is undefined behavior and can cause heap corruption, which is how I spotted this issue.In practice, this issue only occurs when using a program that may
halt_error
, because that is when theexit_code
anderror_message
are set to values other thanjv_invalid
. Subsequent attempts to calljq_start
(which callsjq_reset
internally) after hitting ahalt_error
can cause you to run into this issue.The changes simply reset the
exit_code
and theerror_message
tojv_invalid
(the initial value set injq_init
) after they are freed.