Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2a083ab

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 2e4127b commit 2a083ab

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
@@ -437,6 +437,7 @@ set_locale_and_encoding(void)
437437
char *datcollate_literal;
438438
char *datctype_literal;
439439
char *datlocale_literal = NULL;
440+
char *datlocale_src;
440441
DbLocaleInfo *locale = old_cluster.template0;
441442

442443
prep_status("Setting locale and encoding for new cluster");
@@ -450,12 +451,10 @@ set_locale_and_encoding(void)
450451
datctype_literal = PQescapeLiteral(conn_new_template1,
451452
locale->db_ctype,
452453
strlen(locale->db_ctype));
453-
if (locale->db_locale)
454-
datlocale_literal = PQescapeLiteral(conn_new_template1,
455-
locale->db_locale,
456-
strlen(locale->db_locale));
457-
else
458-
datlocale_literal = pg_strdup("NULL");
454+
datlocale_src = locale->db_locale ? locale->db_locale : "NULL";
455+
datlocale_literal = PQescapeLiteral(conn_new_template1,
456+
datlocale_src,
457+
strlen(datlocale_src));
459458

460459
/* update template0 in new cluster */
461460
if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1700)

0 commit comments

Comments
 (0)