Fix resource leak while reading startup packet.
authorTatsuo Ishii <ishii@postgresql.org>
Sat, 19 Jul 2025 06:48:37 +0000 (15:48 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Sat, 19 Jul 2025 07:02:40 +0000 (16:02 +0900)
Per Coverity.

Backpatch-through: v4.2

src/protocol/child.c

index 53a4cce68dcebc021840f70f9b953d49ca83d488..5ccc1b0749952dc4d72c8565c63d0ca3c124a5c5 100644 (file)
@@ -778,8 +778,11 @@ read_startup_packet(POOL_CONNECTION * cp)
        }
 
        /* The database defaults to their user name. */
-       if (sp->database == NULL || sp->database[0] == '\0')
+       if (sp->database == NULL)
+               sp->database = pstrdup(sp->user);
+       else if (sp->database[0] == '\0')
        {
+               pfree(sp->database);
                sp->database = pstrdup(sp->user);
        }