Re: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c - Mailing list pgsql-hackers

From Mikhail Kot
Subject Re: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c
Date
Msg-id CAAi9E7ge4APjZ_atDce+qjYODnxuRwmNej-9RhL3Ydi3zRs8bw@mail.gmail.com
Whole thread Raw
In response to Re: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c  (Ranier Vilela <ranier.vf@gmail.com>)
Responses 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c
Re: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c
List pgsql-hackers
Hi Michael, Steven, and Ranier,

> Anyway, couldn't we flip the order of the operations in
pgstat_init_entry() so as we do first an allocation and avoid any inconsistency
in the shared state?

The issue is not only in pgstat_init_entry(). Currently it errors on OOM but
this doesn't prevent us from calling pgstat_lock_entry() through
pgstat_get_entry_ref() which accesses a non-initialized lock.

Here's the second version of the patch. Now we remove inserted hash entry
on OOM which would prevent accessing the entry

Attachment

pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: GetNamedLWLockTranche crashes on Windows in normal backend
Next
From: Thomas Munro
Date:
Subject: Re: Solaris compiler status