]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix hash_search to avoid corruption of the hash table on out-of-memory.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Oct 2012 19:24:15 +0000 (15:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Oct 2012 19:24:15 +0000 (15:24 -0400)
commitd01a7442190686a981c0a5ce330e962d8083ac4f
treeb7a2d4f1c338ce56bc152bc5e5e6005b92927e7e
parent823f83d3d53ad2c0e799b1953ed9a1955840f11c
Fix hash_search to avoid corruption of the hash table on out-of-memory.

An out-of-memory error during expand_table() on a palloc-based hash table
would leave a partially-initialized entry in the table.  This would not be
harmful for transient hash tables, since they'd get thrown away anyway at
transaction abort.  But for long-lived hash tables, such as the relcache
hash, this would effectively corrupt the table, leading to crash or other
misbehavior later.

To fix, rearrange the order of operations so that table enlargement is
attempted before we insert a new entry, rather than after adding it
to the hash table.

Problem discovered by Hitoshi Harada, though this is a bit different
from his proposed patch.
src/backend/utils/hash/dynahash.c