0001-dynahash-add-memory-allocation-failure-check.patch
text/x-diff
Filename: 0001-dynahash-add-memory-allocation-failure-check.patch
Type: text/x-diff
Part: 0
Patch
Format: format-patch
Series: patch 0001
Subject: dynahash: add memory allocation failure check The function DynaHashAlloc() calls MemoryContextAllocExtended() with MCXT_ALLOC_NO_OOM and can return a NULL pointer. Fixes: e3860ffa4dd ("Initial pgindent run with pg_bsd_indent version 2.0.") Signed-off-by: Maksim Korotkov <m.korotkov@postgrespro.ru>
| File | + | − |
|---|---|---|
| src/backend/utils/hash/dynahash.c | 6 | 0 |
From 75916a6855bb9e96c7b34b76c0380edc157c150c Mon Sep 17 00:00:00 2001
From: Maksim Korotkov <m.korotkov@postgrespro.ru>
Date: Tue, 22 Apr 2025 12:20:58 +0300
Subject: [PATCH] dynahash: add memory allocation failure check
The function DynaHashAlloc() calls MemoryContextAllocExtended() with MCXT_ALLOC_NO_OOM
and can return a NULL pointer.
Fixes: e3860ffa4dd ("Initial pgindent run with pg_bsd_indent version 2.0.")
Signed-off-by: Maksim Korotkov <m.korotkov@postgrespro.ru>
---
src/backend/utils/hash/dynahash.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index 3f25929f2d8..0cfee50dc21 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -391,6 +391,12 @@ hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
/* Initialize the hash header, plus a copy of the table name */
hashp = (HTAB *) DynaHashAlloc(sizeof(HTAB) + strlen(tabname) + 1);
+ if (unlikely(hashp == NULL))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
+ }
MemSet(hashp, 0, sizeof(HTAB));
hashp->tabname = (char *) (hashp + 1);
--
2.34.1