Skip to content

Commit 9ca2145

Browse files
michaelpqRanierV
andcommitted
pg_upgrade: Fix inconsistency in memory freeing
The function in charge of freeing the memory from a result created by PQescapeIdentifier() has to be PQfreemem(), to ensure that both allocation and free come from libpq. One spot in pg_upgrade was not respecting that for pg_database's datlocale (daticulocale in v16) when the collation provider is libc (aka datlocale/daticulocale is NULL) with an allocation done using pg_strdup() and a free with PQfreemem(). The code is changed to always use PQescapeLiteral() when processing the input. Oversight in 9637bad. This commit is similar to 48e4ae9 and 5b94e27. Author: Michael Paquier <michael@paquier.xyz> Co-authored-by: Ranier Vilela <ranier.vf@gmail.com> Discussion: https://postgr.es/m/Z601RQxTmIUohdkV@paquier.xyz Backpatch-through: 16
1 parent 816149d commit 9ca2145

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ set_locale_and_encoding(void)
383383
char *datcollate_literal;
384384
char *datctype_literal;
385385
char *daticulocale_literal = NULL;
386+
char *daticulocale_src;
386387
DbLocaleInfo *locale = old_cluster.template0;
387388

388389
prep_status("Setting locale and encoding for new cluster");
@@ -396,12 +397,10 @@ set_locale_and_encoding(void)
396397
datctype_literal = PQescapeLiteral(conn_new_template1,
397398
locale->db_ctype,
398399
strlen(locale->db_ctype));
399-
if (locale->db_iculocale)
400-
daticulocale_literal = PQescapeLiteral(conn_new_template1,
401-
locale->db_iculocale,
402-
strlen(locale->db_iculocale));
403-
else
404-
daticulocale_literal = pg_strdup("NULL");
400+
daticulocale_src = locale->db_iculocale ? locale->db_iculocale : "NULL";
401+
daticulocale_literal = PQescapeLiteral(conn_new_template1,
402+
daticulocale_src,
403+
strlen(daticulocale_src));
405404

406405
/* update template0 in new cluster */
407406
if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1500)

0 commit comments

Comments
 (0)