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

Memory leak in pg_query_parse.c:52 #49

Closed
kky0h opened this issue Sep 28, 2018 · 1 comment · Fixed by #56
Closed

Memory leak in pg_query_parse.c:52 #49

kky0h opened this issue Sep 28, 2018 · 1 comment · Fixed by #56

Comments

@kky0h
Copy link

kky0h commented Sep 28, 2018

Hi, I compiled the 'parse_plpgsql.c' and tested it with file "plpgsql_samples.sql". ASan and valgrind find memory leak in pg_query_parse.c:52

==136926==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1 byte(s) in 1 object(s) allocated from:
    #0 0x7fd98c8b32f0 in __strdup (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x752f0)
    #1 0x414020 in pg_query_raw_parse src/pg_query_parse.c:52

SUMMARY: AddressSanitizer: 1 byte(s) leaked in 1 allocation(s).
==137686== Memcheck, a memory error detector
==137686== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==137686== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==137686== Command: ./parse_plpgsql plpgsql_samples.sql
==137686== 
==137686== 
==137686== HEAP SUMMARY:
==137686==     in use at exit: 345,690 bytes in 45 blocks
==137686==   total heap usage: 198 allocs, 153 frees, 1,276,459 bytes allocated
==137686== 
==137686== 1 bytes in 1 blocks are definitely lost in loss record 1 of 31
==137686==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==137686==    by 0x4EBFB49: strdup (strdup.c:42)
==137686==    by 0x414020: pg_query_raw_parse (pg_query_parse.c:52)
==137686==    by 0x4022BC: pg_query_parse_plpgsql (pg_query_parse_plpgsql.c:396)
==137686==    by 0x401785: main (parse_plpgsql.c:44)
==137686== 
==137686== LEAK SUMMARY:
==137686==    definitely lost: 1 bytes in 1 blocks
==137686==    indirectly lost: 0 bytes in 0 blocks
==137686==      possibly lost: 0 bytes in 0 blocks
==137686==    still reachable: 345,689 bytes in 44 blocks
==137686==         suppressed: 0 bytes in 0 blocks
==137686== Reachable blocks (those to which a pointer was found) are not shown.
==137686== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==137686== 
==137686== For counts of detected and suppressed errors, rerun with: -v
==137686== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 1)

After debugging by gdb, I found it seems 'result.stderr_buffer' doesn't free correctly when parse plpgsql.(seems function pg_query_free_parse_result(pg_query_parse.c:116) doesn't be called.)

@lfittl
Copy link
Member

lfittl commented Sep 28, 2018

Thanks for the report!

Would you be available to make a pull request that fixes this issue?

herwinw added a commit to herwinw/libpg_query that referenced this issue Jun 8, 2019
herwinw added a commit to herwinw/libpg_query that referenced this issue Jun 8, 2019
@lfittl lfittl closed this as completed in #56 Jul 1, 2019
lfittl pushed a commit that referenced this issue Jul 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants