Valgrind - showing memory leaks?
Hi Hackers,
I ran a postgres server with valgrind looking for memory leaks at a
particular extension, but I am experiencing something strange. Here are the
steps:
1. PG configured & compile as follows:
---------------------------------------------------
$ ./configure --enable-debug CFLAGS="-ggdb -Og -g3 -fno-omit-frame-pointer"
--enable-cassert \
--enable-rpath --enable-tap-tests --with-ssl=openssl --with-systemd
--enable-depend \
--enable-injection-points --with-liburing --enable-dtrace --prefix=/tmp/pg18
$ make install
2. In terminal-1, PG Server launched as follows:
----------------------------------------------------------------
$ valgrind --leak-check=full --gen-suppressions=all
--suppressions=postgres/src/tools/valgrind.supp \
--time-stamp=yes
--error-markers=VALGRINDERROR-BEGIN,VALGRINDERROR-END
--log-file=/valgrind_%p.log
\
--trace-children=yes /tmp/pg18/bin/postgres -D /tmp/data1
--log_line_prefix="%m %p " \
--log_statement=all --shared_buffers=64MB 2>&1 | tee
/tmp/valgrind_postmaster.log
3. In terminal-2, psql launched as follows:
-------------------------------------------------------
$ /tmp/pg18/bin/psql postgres
psql (18devel)
Type "help" for help.
postgres=# select pg_backend_pid();
pg_backend_pid
----------------
2293900
(1 row)
postgres=# CREATE TABLE tbl1 (scope text NOT NULL);
CREATE TABLE
postgres=# INSERT INTO tbl1 VALUES ('some'),('full');
INSERT 0 2
postgres=# select * from tbl1;
scope
-------
some
full
(2 rows)
postgres=# drop table tbl1;
DROP TABLE
postgres=# \q
Attached is valgrind output generated showing memory leaks.
5. Question:
----------------
I believe that the valgrind should not report any memory leaks in such
simple/common commands. What am I doing wrong here?
Regards,
Yasir Hussain
Data Bene
Attachments:
Hi Yasir
I ran a postgres server with valgrind looking for memory leaks at a particular extension, but I am experiencing something strange. Here are the steps:
[...]
5. Question:
----------------
I believe that the valgrind should not report any memory leaks in such simple/common commands. What am I doing wrong here?
Out-of-the box Valgrind is not aware of the concept of MemoryContexts
in Postgres. If nothing has changed in recent years you should open
src/include/pg_config_manual.h and make sure it has:
```
#define USE_VALGRIND
```
Then rebuild Postgres and run your tests again. Please let us know the results.
--
Best regards,
Aleksander Alekseev