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

From: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: m(dot)korotkov(at)postgrespro(dot)ru, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] dynahash: add memory allocation failure check
Date: 2025-04-24 11:20:52
Message-ID: E48561A7-85E0-4646-9C19-437ACBE291BC@yandex-team.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 24 Apr 2025, at 00:42, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-04-24 11:26:04 Re: Enable data checksums by default
Previous Message Jelte Fennema-Nio 2025-04-24 11:16:07 Re: What's our minimum supported Python version?