diff options
author | Michael Paquier | 2025-02-28 01:15:29 +0000 |
---|---|---|
committer | Michael Paquier | 2025-02-28 01:15:29 +0000 |
commit | 2a083ab807db6d9e2e0e3aa82ee8f6ff9fc44c8d (patch) | |
tree | a985ea474713e98a14f31b7ed40aea3053b72236 | |
parent | 2e4127b6d2d8f3a9d67a21d1905703d5be46970c (diff) |
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 <[email protected]>
Co-authored-by: Ranier Vilela <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 16
-rw-r--r-- | src/bin/pg_upgrade/pg_upgrade.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index d95c491fb57..174cd920840 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -437,6 +437,7 @@ set_locale_and_encoding(void) char *datcollate_literal; char *datctype_literal; char *datlocale_literal = NULL; + char *datlocale_src; DbLocaleInfo *locale = old_cluster.template0; prep_status("Setting locale and encoding for new cluster"); @@ -450,12 +451,10 @@ set_locale_and_encoding(void) datctype_literal = PQescapeLiteral(conn_new_template1, locale->db_ctype, strlen(locale->db_ctype)); - if (locale->db_locale) - datlocale_literal = PQescapeLiteral(conn_new_template1, - locale->db_locale, - strlen(locale->db_locale)); - else - datlocale_literal = pg_strdup("NULL"); + datlocale_src = locale->db_locale ? locale->db_locale : "NULL"; + datlocale_literal = PQescapeLiteral(conn_new_template1, + datlocale_src, + strlen(datlocale_src)); /* update template0 in new cluster */ if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1700) |