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

Fix memory leak in pg_query_fingerprint #141

Merged
merged 3 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pg_query wrappers in other languages:
* Javascript (Browser): [pg-query-emscripten](https://github.com/pganalyze/pg-query-emscripten)
* Python: [psqlparse](https://github.com/alculquicondor/psqlparse), [pglast](https://github.com/lelit/pglast)
* OCaml: [pg_query-ocaml](https://github.com/roddyyaga/pg_query-ocaml)
* Rust: [pg_query.rs](https://github.com/paupino/pg_query.rs)
* Rust: [pg_query.rs](https://github.com/pganalyze/pg_query.rs)

Products, tools and libraries built on pg_query:

Expand Down
1 change: 1 addition & 0 deletions src/pg_query_fingerprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ void pg_query_free_fingerprint_result(PgQueryFingerprintResult result)
if (result.error) {
free(result.error->message);
free(result.error->filename);
free(result.error->funcname);
free(result.error);
}

Expand Down
8 changes: 8 additions & 0 deletions test/fingerprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ int main()
pg_query_free_fingerprint_result(result);
}

// Ensures that there isn't a memory leak in the error case
PgQueryFingerprintResult result = pg_query_fingerprint("SELECT !");
if (strcmp(result.error->message, "syntax error at end of input") != 0) {
printf("\nERROR mismatch: %s\n", result.error->message);
return EXIT_FAILURE;
}
pg_query_free_fingerprint_result(result);

printf("\n");

pg_query_exit();
Expand Down