]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix memory leak in new GUC check_hook
authorÁlvaro Herrera <alvherre@kurilemu.de>
Tue, 17 Feb 2026 15:38:24 +0000 (16:38 +0100)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Tue, 17 Feb 2026 15:38:24 +0000 (16:38 +0100)
Commit 38e0190ced71 forgot to pfree() an allocation (freed in other
places of the same function) in only one of several spots in
check_log_min_messages().  Per Coverity.  Add that.

While at it, avoid open-coding guc_strdup().  The new coding does a
strlen() that wasn't there before, but I doubt it's measurable.

src/backend/utils/error/elog.c

index 59315e94e3e5480c457c910e129c69724b11126c..cb1c9d85ffe46821391737f0593203c010b8baa5 100644 (file)
@@ -2363,11 +2363,12 @@ lmm_fail:
                        appendStringInfo(&buf, ", %s", elem);
        }
 
-       result = (char *) guc_malloc(LOG, buf.len + 1);
+       result = guc_strdup(LOG, buf.data);
        if (!result)
+       {
+               pfree(buf.data);
                return false;
-       memcpy(result, buf.data, buf.len);
-       result[buf.len] = '\0';
+       }
 
        guc_free(*newval);
        *newval = result;