Skip to content

Commit 0851b65

Browse files
committed
Fix unintentional 'NULL' string literal in pg_upgrade.
Introduced in 2a083ab. Note: backport of commit 9451262, 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
1 parent 5e7be43 commit 0851b65

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ set_locale_and_encoding(void)
408408
char *datcollate_literal;
409409
char *datctype_literal;
410410
char *datlocale_literal = NULL;
411-
char *datlocale_src;
412411
DbLocaleInfo *locale = old_cluster.template0;
413412

414413
prep_status("Setting locale and encoding for new cluster");
@@ -422,10 +421,13 @@ set_locale_and_encoding(void)
422421
datctype_literal = PQescapeLiteral(conn_new_template1,
423422
locale->db_ctype,
424423
strlen(locale->db_ctype));
425-
datlocale_src = locale->db_locale ? locale->db_locale : "NULL";
426-
datlocale_literal = PQescapeLiteral(conn_new_template1,
427-
datlocale_src,
428-
strlen(datlocale_src));
424+
425+
if (locale->db_locale)
426+
datlocale_literal = PQescapeLiteral(conn_new_template1,
427+
locale->db_locale,
428+
strlen(locale->db_locale));
429+
else
430+
datlocale_literal = "NULL";
429431

430432
/* update template0 in new cluster */
431433
if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1700)
@@ -469,7 +471,8 @@ set_locale_and_encoding(void)
469471

470472
PQfreemem(datcollate_literal);
471473
PQfreemem(datctype_literal);
472-
PQfreemem(datlocale_literal);
474+
if (locale->db_locale)
475+
PQfreemem(datlocale_literal);
473476

474477
PQfinish(conn_new_template1);
475478

0 commit comments

Comments
 (0)