pgsql: Fix hash_search to avoid corruption of the hash table on out-of- - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix hash_search to avoid corruption of the hash table on out-of-
Date
Msg-id E1TPIC3-0001ff-6x@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/8a3249f12447468c4ac5a3b91cfdad5573e2b660

Modified Files
--------------
src/backend/utils/hash/dynahash.c |   46 ++++++++++++++++++++++++-------------
1 files changed, 30 insertions(+), 16 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix ruleutils to print "INSERT INTO foo DEFAULT VALUES" correctl
Next
From: Tom Lane
Date:
Subject: pgsql: Fix hash_search to avoid corruption of the hash table on out-of-