Closed yingjunwu closed 3 years ago
@yingjunwu Thanks for reaching out & trying out libpg_query!
This is a bit complicated (I was debugging this with Valgrind the other day, in fact), and is caused by the Postgres top-level memory context, which is left allocated even after the parsing of the query (and it gets reused with the next query that gets parsed).
In the upcoming Postgres 13 branch this is addressed with an explicit function: https://github.com/lfittl/libpg_query/commit/5da2bf49512a5809fab9e45a50272e71e54c82c4
For now, I would recommend using a suppression list with Valgrind. This is not a memory leak that would grow beyond the 16kb referenced by Valgrind here, and is actually how Postgres itself works (since this memory just gets freed when Postgres shuts down).
@lfittl thank you for super prompt reply! Cool I'll supress it for now and will wait for PG 13!
@yingjunwu I've now backported this for the v10 branch as well, you can find the PR here:
https://github.com/lfittl/libpg_query/pull/83
(this also now tests that the library has a clean Valgrind run)
Hi @lfittl thanks for the nice work! I may got wrong but whether it could also fix the valgrind complaint that can be repro'd using the following command:
git clone -b 10-latest git://github.com/lfittl/libpg_query
cd libpg_query
make
cd example
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./simple
Seems that it still reports the same issue from my side (git hash: 2d0200c10cd60c1433b9433cb65c7e5df22dbd11). Yes I know it's not real mem leak :-) For now I still use valgrind.supp to suppress the false complaint.
@yingjunwu Thats mostly because the examples currently don't call pg_query_exit();
- if you add that it should result in a clean Valgrind run.
Hi @lfittl I have confirmed that valgrind no longer reports any issues after adding pg_query_exit()
in simple.c
. Thank you for your nice work!
@yingjunwu Perfect, thanks for confirming - I'll close this issue.
Hi I am new to
libpg_query
and found a potential memory leak in the library. To repro, run:output:
I wonder whether this is really a memory leak? Thank you!