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

Commit ee78823

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 f903d4d commit ee78823

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/bin/pg_upgrade/pg_upgrade.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ set_locale_and_encoding(void)
408408
char *datcollate_literal;
409409
char *datctype_literal;
410410
char *datlocale_literal = NULL;
411+
char *datlocale_src;
411412
DbLocaleInfo *locale = old_cluster.template0;
412413

413414
prep_status("Setting locale and encoding for new cluster");
@@ -421,12 +422,10 @@ set_locale_and_encoding(void)
421422
datctype_literal = PQescapeLiteral(conn_new_template1,
422423
locale->db_ctype,
423424
strlen(locale->db_ctype));
424-
if (locale->db_locale)
425-
datlocale_literal = PQescapeLiteral(conn_new_template1,
426-
locale->db_locale,
427-
strlen(locale->db_locale));
428-
else
429-
datlocale_literal = pg_strdup("NULL");
425+
datlocale_src = locale->db_locale ? locale->db_locale : "NULL";
426+
datlocale_literal = PQescapeLiteral(conn_new_template1,
427+
datlocale_src,
428+
strlen(datlocale_src));
430429

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

0 commit comments

Comments
 (0)