Fix unintentional 'NULL' string literal in pg_upgrade.
authorJeff Davis <jdavis@postgresql.org>
Sun, 6 Apr 2025 16:14:42 +0000 (09:14 -0700)
committerJeff Davis <jdavis@postgresql.org>
Sun, 6 Apr 2025 16:14:42 +0000 (09:14 -0700)
Introduced in 2a083ab807.

Note: backport of commit 945126234b, which was missed at the time.

Discussion: https://postgr.es/m/e852442da35b4f31acc600ed98bbee0f12e65e0c.camel@j-davis.com
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Backpatch-through: 16

src/bin/pg_upgrade/pg_upgrade.c

index 846fd65793f97629c69f60313d5bf144142c612c..6359109c721d3f06859c65e888d5dfa9135859f1 100644 (file)
@@ -383,7 +383,6 @@ set_locale_and_encoding(void)
    char       *datcollate_literal;
    char       *datctype_literal;
    char       *daticulocale_literal = NULL;
-   char       *daticulocale_src;
    DbLocaleInfo *locale = old_cluster.template0;
 
    prep_status("Setting locale and encoding for new cluster");
@@ -397,10 +396,13 @@ set_locale_and_encoding(void)
    datctype_literal = PQescapeLiteral(conn_new_template1,
                                       locale->db_ctype,
                                       strlen(locale->db_ctype));
-   daticulocale_src = locale->db_iculocale ? locale->db_iculocale : "NULL";
-   daticulocale_literal = PQescapeLiteral(conn_new_template1,
-                                          daticulocale_src,
-                                          strlen(daticulocale_src));
+
+   if (locale->db_iculocale)
+       daticulocale_literal = PQescapeLiteral(conn_new_template1,
+                                              locale->db_iculocale,
+                                              strlen(locale->db_iculocale));
+   else
+       daticulocale_literal = "NULL";
 
    /* update template0 in new cluster */
    if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1500)
@@ -430,7 +432,8 @@ set_locale_and_encoding(void)
 
    PQfreemem(datcollate_literal);
    PQfreemem(datctype_literal);
-   PQfreemem(daticulocale_literal);
+   if (locale->db_iculocale)
+       PQfreemem(daticulocale_literal);
 
    PQfinish(conn_new_template1);