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 06:48:37 +0000 (15:48 +0900)
Per Coverity.

Backpatch-through: v4.2

src/protocol/child.c

index cf2161806b38d31d4497ddd03c478b666bda5f46..87de2caac10b7b3173ee230137b7d3d8d2d55878 100644 (file)
@@ -772,8 +772,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);
        }