use valgrind --leak-check=yes to detect memory leak

From: Alex <zhihui(dot)fan1213(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: use valgrind --leak-check=yes to detect memory leak
Date: 2019-08-14 06:33:54
Message-ID: CAKU4AWoDby5gnp6nd1mMtsT+0vmHjjDyhuXjgGZTDcKsgxr-3g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I want to use valgrind to detect memory leak issue. Then I run into 2
problems I want to confirm them here.

Q1: can I use 'leak-check=yes' to detect memory leak issue?
1. In https://wiki.postgresql.org/wiki/Valgrind, the wiki indicates to
use '--leak-check=no'
2. in https://github.com/afiskon/pgscripts/blob/master/valgrind.sh#L55,
it use 'leak-check=no' as well with the wold "No point to check for memory
leaks, Valgrind doesn't understand MemoryContexts and stuff"
3. Per my understanding, if we build pg with USE_VALGRIND, then we can
use 'leak-check=yes' to detect memory leak issue, the idea here is
a). valgrind can't understand MemoryContext,
b). with USE_VALGRIND, pg use ` VALGRIND_MEMPOOL_ALLOC` and `
VALGRIND_MEMPOOL_FREE` whenever we we allocate and free memory in
MemoryContext
c). finally, valgrind check the valgrind_mempool to know which memory
is leak.
So the answer should be "yes, we can use "leak-check=yes" to detect memory
leak issue?

Q2: do we check memory leak for some new commits or we can ignore them
based on we use memory context carefully? If we want to check memory leak
for some new commits, how to handle the existing memory leak case?

with `valgrind --leak-check=yes --suppressions=src/tools/valgrind.supp ...`
and run `make installcheck` on an unmodified version (commit
d06fe6ce2c79420fd19ac89ace81b66579f08493) , I run into 711 memory leaks
with `match-leak-kinds: definite`. if we want to check memory leak for
new commits, this should be a kind of troubles. how do you do with this
everyday?

Thanks

Attachment Content-Type Size
mem_leak_report.txt text/plain 284.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2019-08-14 06:57:45 Re: POC: Cleaning up orphaned files using undo logs
Previous Message David Rowley 2019-08-14 06:11:06 Re: Custom table AMs need to include heapam.h because of BulkInsertState