Re: [PATCH] dynahash: add memory allocation failure check

x4mmm@yandex-team.ru

From: Andrey Borodin <x4mmm@yandex-team.ru>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: m.korotkov@postgrespro.ru, pgsql-hackers@postgresql.org
Date: 2025-04-24T11:20:52Z
Lists: pgsql-hackers

> On 24 Apr 2025, at 00:42, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
> - hashp = (HTAB *) DynaHashAlloc(sizeof(HTAB) + strlen(tabname) + 1);
> + hashp = (HTAB *) MemoryContextAlloc(CurrentDynaHashCxt,
> + sizeof(HTAB) + strlen(tabname) + 1);

This seems correct to me.

While fixing this maybe use MemoryContextAllocZero() instead of subsequent MemSet()?

But this might unroll loop of unnecessary beautifications like DynaHashAlloc() calling Assert(MemoryContextIsValid(CurrentDynaHashCxt)) just before MemoryContextAllocExtended() will repeat same exercise.


Best regards, Andrey Borodin.


Commits

  1. Avoid possibly-theoretical OOM crash hazard in hash_create().