Re: Fix some ubsan/asan related issues

Tristan Partin <tristan@partin.io>

From: "Tristan Partin" <tristan@partin.io>
To: "Junwang Zhao" <zhjwpku@gmail.com>
Cc: "Andres Freund" <andres@anarazel.de>, "Alexander Lakhin" <exclusion@gmail.com>, "pgsql-hackers" <pgsql-hackers@postgresql.org>, "Heikki Linnakangas" <hlinnaka@iki.fi>
Date: 2024-10-02T04:02:27Z
Lists: pgsql-hackers
On Mon Sep 16, 2024 at 9:29 AM EDT, Junwang Zhao wrote:
> I tried your v1-0002, it works at compile phase but failed to run initdb
> with the following leak detected:
>
> =================================================================
> ==64983==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 248 byte(s) in 1 object(s) allocated from:
>     #0 0x7fc7729df9cf in __interceptor_malloc
> ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
>     #1 0x55bff5480e8b in save_ps_display_args
> ../postgres/src/backend/utils/misc/ps_status.c:190
>     #2 0x55bff4a5a298 in main ../postgres/src/backend/main/main.c:90
>     #3 0x7fc771924249 in __libc_start_call_main
> ../sysdeps/nptl/libc_start_call_main.h:58
>
> Indirect leak of 19 byte(s) in 1 object(s) allocated from:
>     #0 0x7fc77299777b in __interceptor_strdup
> ../../../../src/libsanitizer/asan/asan_interceptors.cpp:439
>     #1 0x55bff5480f41 in save_ps_display_args
> ../postgres/src/backend/utils/misc/ps_status.c:198
>     #2 0x55bff4a5a298 in main ../postgres/src/backend/main/main.c:90
>     #3 0x7fc771924249 in __libc_start_call_main
> ../sysdeps/nptl/libc_start_call_main.h:58
>
> I worked around by moving *new_environ* as a global variable, I think this is
> false positive report so maybe this deserves a patch?
>
> I tried to apply your v2 patch set but v2-0004 seems out of date.

Thanks for giving it a try Junwang. I'll rebase this, hopefully tomorrow 
and give it another push.

-- 
Tristan Partin
Neon (https://neon.tech)