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

Backpatch-through: v4.2

src/protocol/child.c

index 2f4935e7063c57035339e4807e71363b4b8ff235..c83d537d16cdcd641398cc63bb575f0996ca935d 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2024     PgPool Global Development Group
+ * Copyright (c) 2003-2025     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -753,9 +753,12 @@ read_startup_packet(POOL_CONNECTION * cp)
                                 errdetail("no PostgreSQL user name specified in startup packet")));
        }
 
-       /* The database defaults to ther user name. */
-       if (sp->database == NULL || sp->database[0] == '\0')
+       /* The database defaults to their user name. */
+       if (sp->database == NULL)
+               sp->database = pstrdup(sp->user);
+       else if (sp->database[0] == '\0')
        {
+               pfree(sp->database);
                sp->database = pstrdup(sp->user);
        }