Thread: BUG #18983: Problems with Postgres "make check" under ASAN

BUG #18983: Problems with Postgres "make check" under ASAN

From
PG Bug reporting form
Date:
The following bug has been logged on the website:

Bug reference:      18983
Logged by:          Dmitry Kovalenko
Email address:      d.kovalenko@postgrespro.ru
PostgreSQL version: 18beta1
Operating system:   Ubuntu 2024.04
Description:

Hello,
We want testing our components and extensions for Postgres under ASAN but
the problems within original PG code does not allow to do it easily.
I won't describe each detected problems but provide these things:
1) Link to clone of the current master source that is able to pass "make
check"
https://github.com/dmitry-lipetsk/postgres/commits/D20250709_001--memory_leaks--master/
2) link to archive with intermediate results.
https://dropmefiles.com/FV9oF
Link is valid within 14 days.
You can find there the logs about different memory leaks in PG components.
--- The first error was:
==1606829==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 552 byte(s) in 1 object(s) allocated from:
    #0 0x5a6fd925b76f in __interceptor_malloc

(/home/dima/MY/Work/CurrentTasks/2025/POSTGRES/2025_06_17__001--mem_leaks/n002/work01/tmp_install/home/dima/MY/Work/CurrentTasks/2025/POSTGRES/2025_06_17__001--m
em_leaks/n002/work01/install/bin/postgres+0x344876f) (BuildId:
11244cf09fb880f4c1e1ed11ac039b3246818fa5)
    #1 0x5a6fdb46df3c in save_ps_display_args

/home/dima/MY/Work/CurrentTasks/2025/POSTGRES/2025_06_17__001--mem_leaks/n002/work01/src/backend/utils/misc/ps_status.c:192
    #2 0x5a6fda17850e in main
/home/dima/MY/Work/CurrentTasks/2025/POSTGRES/2025_06_17__001--mem_leaks/n002/work01/src/backend/main/main.c:104
    #3 0x7a120762a1c9 in __libc_start_call_main
../sysdeps/nptl/libc_start_call_main.h:58
    #4 0x7a120762a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #5 0x5a6fd91a3694 in _start

(/home/dima/MY/Work/CurrentTasks/2025/POSTGRES/2025_06_17__001--mem_leaks/n002/work01/tmp_install/home/dima/MY/Work/CurrentTasks/2025/POSTGRES/2025_06_17__001--mem_leaks/n002/
work01/install/bin/postgres+0x3390694) (BuildId:
11244cf09fb880f4c1e1ed11ac039b3246818fa5)
SUMMARY: AddressSanitizer: 552 byte(s) leaked in 1 allocation(s).
---
You can run "make check" for these components, too:
- initdb
- psql
- pg_config
- pg_controldata
---  How did I build server:
1) CPPFLAGS="-O0 -g3 -fsanitize=address -fsanitize=undefined
-fno-sanitize=nonnull-attribute -fno-sanitize-recover
-fno-sanitize=alignment -fstack-protector" LDFLAGS="-fsanitize=address
-fsanitize=undefined -static-libasan" ./configure --prefix=`realpath
.`/install --enable-tap-tests --with-zlib --enable-cassert --with-openssl
--enable-debug --without-readline --with-lz4 --with-zstd --with-libxml
2) make -j 8 install
3) make -j 8 -C contrib install
---  How did I run tests:
1) export

ASAN_OPTIONS="abort_on_error=1:disable_coredump=0:strict_string_checks=1:check_initialization_order=1:strict_init_order=1:detect_odr_violation=0:detect_stack_use_after_return=0"
2) make check
--- Two kind of changes
1) I release memory/resource immediately.
2) I append allocated memory in global list and free it before exit.
See cleanup_global_data and relaxmem (common/relaxmem.h(c)).
---
I hope, this work will be useful for PostgreSQL.
---
Thanks&Regards,
Dmitry Kovalenko


PG Bug reporting form <noreply@postgresql.org> writes:
> We want testing our components and extensions for Postgres under ASAN but
> the problems within original PG code does not allow to do it easily.
> I won't describe each detected problems but provide these things:
> 1) Link to clone of the current master source that is able to pass "make
> check"
> https://github.com/dmitry-lipetsk/postgres/commits/D20250709_001--memory_leaks--master/

We do not accept patch submissions in this way.  Please email a patch
file to the pgsql-hackers list.

FWIW, if this is mostly about memory leaks, there's already work
in progress at

https://www.postgresql.org/message-id/flat/285483.1746756246@sss.pgh.pa.us

            regards, tom lane