Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jq_fuzz_execute: fix memory leak #2960

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/jq_fuzz_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
jv_free(actual);
}
jv_free(next);
} else {
// Only free if input is invalid as otherwise jq_teardown
// frees it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if understand it correctly: jq_parse will always return something allocated. If valid the input argument will end up on the stack by jq_start and freed during teardown. If invalid it needs to be freed explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's how I understand it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is invalid"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is invalid"?

Ah yes, good catch. Fixed.

jv_free(input);
}

// Do not free "input" as this is handled by jq_teardown.
}
}
jq_teardown(&jq);
Expand Down