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:46 +0000 (16:02 +0900)
Per Coverity.

Backpatch-through: v4.2

src/protocol/child.c

index 8864931541de7a070d939dbc721db4c6fe58cc00..40c0278f7db081d99ea0f0b8aed86dd5bd8dfa5b 100644 (file)
@@ -766,8 +766,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);
        }