mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	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 in9637badd9f. This commit is similar to48e4ae9a07and5b94e27534. 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
This commit is contained in:
		@@ -437,6 +437,7 @@ set_locale_and_encoding(void)
 | 
				
			|||||||
	char	   *datcollate_literal;
 | 
						char	   *datcollate_literal;
 | 
				
			||||||
	char	   *datctype_literal;
 | 
						char	   *datctype_literal;
 | 
				
			||||||
	char	   *datlocale_literal = NULL;
 | 
						char	   *datlocale_literal = NULL;
 | 
				
			||||||
 | 
						char	   *datlocale_src;
 | 
				
			||||||
	DbLocaleInfo *locale = old_cluster.template0;
 | 
						DbLocaleInfo *locale = old_cluster.template0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	prep_status("Setting locale and encoding for new cluster");
 | 
						prep_status("Setting locale and encoding for new cluster");
 | 
				
			||||||
@@ -450,12 +451,10 @@ set_locale_and_encoding(void)
 | 
				
			|||||||
	datctype_literal = PQescapeLiteral(conn_new_template1,
 | 
						datctype_literal = PQescapeLiteral(conn_new_template1,
 | 
				
			||||||
									   locale->db_ctype,
 | 
														   locale->db_ctype,
 | 
				
			||||||
									   strlen(locale->db_ctype));
 | 
														   strlen(locale->db_ctype));
 | 
				
			||||||
	if (locale->db_locale)
 | 
						datlocale_src = locale->db_locale ? locale->db_locale : "NULL";
 | 
				
			||||||
	datlocale_literal = PQescapeLiteral(conn_new_template1,
 | 
						datlocale_literal = PQescapeLiteral(conn_new_template1,
 | 
				
			||||||
											locale->db_locale,
 | 
															datlocale_src,
 | 
				
			||||||
											strlen(locale->db_locale));
 | 
															strlen(datlocale_src));
 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
		datlocale_literal = pg_strdup("NULL");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* update template0 in new cluster */
 | 
						/* update template0 in new cluster */
 | 
				
			||||||
	if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1700)
 | 
						if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1700)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user