Обсуждение: Clang Address Sanitizer (Postgres14) Detected Memory Leaks

Поиск
Список
Период
Сортировка

Clang Address Sanitizer (Postgres14) Detected Memory Leaks

От
Ranier Vilela
Дата:
Hi,

Is this something to worry about, or is it another problem with the analysis tool, that nobody cares about?
clang 10 (64 bits)
postgres 14 (latest)

31422==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4560 byte(s) in 1 object(s) allocated from:
    #0 0x50e33d in malloc (/usr/src/postgres/tmp_install/usr/local/pgsql/bin/postgres+0x50e33d)
    #1 0x186d52f in ConvertTimeZoneAbbrevs /usr/src/postgres/src/backend/utils/adt/datetime.c:4511:8
    #2 0x1d9b5e9 in load_tzoffsets /usr/src/postgres/src/backend/utils/misc/tzparser.c:465:12
    #3 0x1d8ca3f in check_timezone_abbreviations /usr/src/postgres/src/backend/utils/misc/guc.c:11389:11
    #4 0x1d6a398 in call_string_check_hook /usr/src/postgres/src/backend/utils/misc/guc.c:11056:7
    #5 0x1d68f29 in parse_and_validate_value /usr/src/postgres/src/backend/utils/misc/guc.c:6870:10
    #6 0x1d6567d in set_config_option /usr/src/postgres/src/backend/utils/misc/guc.c:7473:11
    #7 0x1d7f8f4 in ProcessGUCArray /usr/src/postgres/src/backend/utils/misc/guc.c:10608:10
    #8 0x9d0c8d in ApplySetting /usr/src/postgres/src/backend/catalog/pg_db_role_setting.c:256:4
    #9 0x1d4ad93 in process_settings /usr/src/postgres/src/backend/utils/init/postinit.c:1174:2
    #10 0x1d48e39 in InitPostgres /usr/src/postgres/src/backend/utils/init/postinit.c:1059:2
    #11 0x14a2c1a in BackgroundWorkerInitializeConnectionByOid /usr/src/postgres/src/backend/postmaster/postmaster.c:5758:2
    #12 0x853feb in ParallelWorkerMain /usr/src/postgres/src/backend/access/transam/parallel.c:1373:2
    #13 0x146e5fb in StartBackgroundWorker /usr/src/postgres/src/backend/postmaster/bgworker.c:813:2
    #14 0x14af69b in do_start_bgworker /usr/src/postgres/src/backend/postmaster/postmaster.c:5879:4
    #15 0x14a1487 in maybe_start_bgworkers /usr/src/postgres/src/backend/postmaster/postmaster.c:6104:9
    #16 0x149e5aa in sigusr1_handler /usr/src/postgres/src/backend/postmaster/postmaster.c:5269:3
    #17 0x7fcffa75a3bf  (/lib/x86_64-linux-gnu/libpthread.so.0+0x153bf)
    #18 0x149d655 in PostmasterMain /usr/src/postgres/src/backend/postmaster/postmaster.c:1414:11
    #19 0x108402e in main /usr/src/postgres/src/backend/main/main.c:209:3
    #20 0x7fcffa54e0b2 in __libc_start_main /build/glibc-YYA7BZ/glibc-2.31/csu/../csu/libc-start.c:308:16

Direct leak of 1020 byte(s) in 15 object(s) allocated from:
    #0 0x4fa6e4 in strdup (/usr/src/postgres/tmp_install/usr/local/pgsql/bin/postgres+0x4fa6e4)
    #1 0x1d6a1c7 in guc_strdup /usr/src/postgres/src/backend/utils/misc/guc.c:4889:9
    #2 0x1d7efc7 in set_config_sourcefile /usr/src/postgres/src/backend/utils/misc/guc.c:7696:15
    #3 0x1d7c95e in ProcessConfigFileInternal /usr/src/postgres/src/backend/utils/misc/guc-file.l:478:4
    #4 0x1d5b33f in ProcessConfigFile /usr/src/postgres/src/backend/utils/misc/guc-file.l:156:9
    #5 0x1d5ae7d in SelectConfigFiles /usr/src/postgres/src/backend/utils/misc/guc.c:5674:2
    #6 0x149b6ce in PostmasterMain /usr/src/postgres/src/backend/postmaster/postmaster.c:884:7

Ranier Vilela

Re: Clang Address Sanitizer (Postgres14) Detected Memory Leaks

От
Tom Lane
Дата:
Ranier Vilela <ranier.vf@gmail.com> writes:
> Is this something to worry about, or is it another problem with the
> analysis tool, that nobody cares about?

As far as the first one goes, I'd bet on buggy analysis tool.
The complained-of allocation is evidently for the "extra" state
associated with the timezone GUC variable, and AFAICS guc.c is
quite careful not to leak those.  It is true that the block will
still be allocated at process exit, but that doesn't make it a leak.

I did not trace the second one in any detail, but I don't believe
guc.c leaks sourcefile strings either.  There's only one place
where it overwrites them, and that place frees the old value.

If these allocations do genuinely get leaked in some code path,
this report is of exactly zero help in finding where; and I'm
afraid I'm not very motivated to go looking for a bug that probably
doesn't exist.

            regards, tom lane



Re: Clang Address Sanitizer (Postgres14) Detected Memory Leaks

От
Ranier Vilela
Дата:
Em qui., 27 de ago. de 2020 às 12:46, Tom Lane <tgl@sss.pgh.pa.us> escreveu:
Ranier Vilela <ranier.vf@gmail.com> writes:
> Is this something to worry about, or is it another problem with the
> analysis tool, that nobody cares about?

As far as the first one goes, I'd bet on buggy analysis tool.
The complained-of allocation is evidently for the "extra" state
associated with the timezone GUC variable, and AFAICS guc.c is
quite careful not to leak those.  It is true that the block will
still be allocated at process exit, but that doesn't make it a leak.

I did not trace the second one in any detail, but I don't believe
guc.c leaks sourcefile strings either.  There's only one place
where it overwrites them, and that place frees the old value.

If these allocations do genuinely get leaked in some code path,
this report is of exactly zero help in finding where; and I'm
afraid I'm not very motivated to go looking for a bug that probably
doesn't exist.
Hi Tom,
thanks for taking a look at this.

I tried to find where the zone table is freed, without success.
It would be a big surprise for me, if this tool is buggy.
Anyway, it's just a sample of the total report, which is 10 mb (postmaster.log), done with the regression tests.

regards,
Ranier Vilela

Re: Clang Address Sanitizer (Postgres14) Detected Memory Leaks

От
Ranier Vilela
Дата:
More reports.
Memory Sanitizer:

running bootstrap script ... ==40179==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x538cfc1 in pg_comp_crc32c_sb8 /usr/src/postgres/src/port/pg_crc32c_sb8.c:80:4
    #1 0x533a0c0 in pg_comp_crc32c_choose /usr/src/postgres/src/port/pg_crc32c_sse42_choose.c:61:9
    #2 0xebbdae in BootStrapXLOG /usr/src/postgres/src/backend/access/transam/xlog.c:5293:2
    #3 0xfc5867 in AuxiliaryProcessMain /usr/src/postgres/src/backend/bootstrap/bootstrap.c:437:4
    #4 0x26a12c3 in main /usr/src/postgres/src/backend/main/main.c:201:3
    #5 0x7f035d0e90b2 in __libc_start_main /build/glibc-YYA7BZ/glibc-2.31/csu/../csu/libc-start.c:308:16
    #6 0x495afd in _start (/usr/src/postgres/tmp_install/usr/local/pgsql/bin/postgres+0x495afd)

  Uninitialized value was stored to memory at
    #0 0x538cbaa in pg_comp_crc32c_sb8 /usr/src/postgres/src/port/pg_crc32c_sb8.c:72:15
    #1 0x533a0c0 in pg_comp_crc32c_choose /usr/src/postgres/src/port/pg_crc32c_sse42_choose.c:61:9
    #2 0xebbdae in BootStrapXLOG /usr/src/postgres/src/backend/access/transam/xlog.c:5293:2
    #3 0xfc5867 in AuxiliaryProcessMain /usr/src/postgres/src/backend/bootstrap/bootstrap.c:437:4
    #4 0x26a12c3 in main /usr/src/postgres/src/backend/main/main.c:201:3
    #5 0x7f035d0e90b2 in __libc_start_main /build/glibc-YYA7BZ/glibc-2.31/csu/../csu/libc-start.c:308:16

  Uninitialized value was stored to memory at
    #0 0x538c836 in pg_comp_crc32c_sb8 /usr/src/postgres/src/port/pg_crc32c_sb8.c:57:11
    #1 0x533a0c0 in pg_comp_crc32c_choose /usr/src/postgres/src/port/pg_crc32c_sse42_choose.c:61:9
    #2 0xebbdae in BootStrapXLOG /usr/src/postgres/src/backend/access/transam/xlog.c:5293:2
    #3 0xfc5867 in AuxiliaryProcessMain /usr/src/postgres/src/backend/bootstrap/bootstrap.c:437:4
    #4 0x26a12c3 in main /usr/src/postgres/src/backend/main/main.c:201:3
    #5 0x7f035d0e90b2 in __libc_start_main /build/glibc-YYA7BZ/glibc-2.31/csu/../csu/libc-start.c:308:16

  Uninitialized value was stored to memory at
    #0 0x49b666 in __msan_memcpy (/usr/src/postgres/tmp_install/usr/local/pgsql/bin/postgres+0x49b666)
    #1 0xebbb70 in BootStrapXLOG /usr/src/postgres/src/backend/access/transam/xlog.c:5288:2
    #2 0xfc5867 in AuxiliaryProcessMain /usr/src/postgres/src/backend/bootstrap/bootstrap.c:437:4
    #3 0x26a12c3 in main /usr/src/postgres/src/backend/main/main.c:201:3
    #4 0x7f035d0e90b2 in __libc_start_main /build/glibc-YYA7BZ/glibc-2.31/csu/../csu/libc-start.c:308:16

  Uninitialized value was created by an allocation of 'checkPoint' in the stack frame of function 'BootStrapXLOG'
    #0 0xeb9f50 in BootStrapXLOG /usr/src/postgres/src/backend/access/transam/xlog.c:5194

This line solve the alert:
(xlog.c) 5193:
memset(&checkPoint, 0, sizeof(checkPoint));

I'm starting to doubt this tool.

regards,
Ranier Vilela

Re: Clang Address Sanitizer (Postgres14) Detected Memory Leaks

От
Tom Lane
Дата:
Ranier Vilela <ranier.vf@gmail.com> writes:
> More reports.
> Memory Sanitizer:
> running bootstrap script ... ==40179==WARNING: MemorySanitizer:
> use-of-uninitialized-value

If you're going to run tests like that, you need to account for the
known exceptions shown in src/tools/valgrind.supp.

            regards, tom lane