From: Michael Paquier Date: Fri, 28 Feb 2025 01:15:34 +0000 (+0900) Subject: pg_upgrade: Fix inconsistency in memory freeing X-Git-Tag: REL_16_9~73 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9ca2145b00fb5d6272e87f274b0f40df77d81a51;p=thirdparty%2Fpostgresql.git 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 9637badd9f92. This commit is similar to 48e4ae9a0707 and 5b94e2753439. Author: Michael Paquier Co-authored-by: Ranier Vilela Discussion: https://postgr.es/m/Z601RQxTmIUohdkV@paquier.xyz Backpatch-through: 16 --- diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index 4562dafcff5..846fd65793f 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -383,6 +383,7 @@ 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"); @@ -396,12 +397,10 @@ set_locale_and_encoding(void) datctype_literal = PQescapeLiteral(conn_new_template1, locale->db_ctype, strlen(locale->db_ctype)); - if (locale->db_iculocale) - daticulocale_literal = PQescapeLiteral(conn_new_template1, - locale->db_iculocale, - strlen(locale->db_iculocale)); - else - daticulocale_literal = pg_strdup("NULL"); + daticulocale_src = locale->db_iculocale ? locale->db_iculocale : "NULL"; + daticulocale_literal = PQescapeLiteral(conn_new_template1, + daticulocale_src, + strlen(daticulocale_src)); /* update template0 in new cluster */ if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1500)