Avoid low-probability crash on out-of-memory.
authorTom Lane <[email protected]>
Thu, 5 Dec 2024 17:54:41 +0000 (12:54 -0500)
committerTom Lane <[email protected]>
Thu, 5 Dec 2024 17:54:41 +0000 (12:54 -0500)
check_restrict_nonsystem_relation_kind() correctly uses guc_malloc()
in v16 and later.  But in older branches it must use malloc()
directly, and it forgot to check for failure return.
Faulty backing of 66e94448a.

Karina Litskevich

Discussion: https://postgr.es/m/CACiT8iZ=atkguKVbpN4HmJFMb4+T9yEowF5JuPZG8W+kkZ9L6w@mail.gmail.com

src/backend/tcop/postgres.c

index ec630b449166fad5ac15a7354dcb017109c3523d..8ad28dce2b7b1d9a22cdba0857d08e7f2dc31617 100644 (file)
@@ -3489,6 +3489,11 @@ check_restrict_nonsystem_relation_kind(char **newval, void **extra, GucSource so
 
    /* Save the flags in *extra, for use by the assign function */
    *extra = malloc(sizeof(int));
+   if (*extra == NULL)
+       ereport(ERROR,
+               (errcode(ERRCODE_OUT_OF_MEMORY),
+                errmsg("out of memory")));
+
    *((int *) *extra) = flags;
 
    return true;