1212 *
1313 *******************************************************************************
1414 *
15- * Copyright (c) 2016-2022 , Postgres Professional
15+ * Copyright (c) 2016-2023 , Postgres Professional
1616 *
1717 * IDENTIFICATION
1818 * aqo/hash.c
@@ -157,6 +157,8 @@ get_grouped_exprs_hash(int child_fss, List *group_exprs)
157157 final_hashes [0 ] = child_fss ;
158158 final_hashes [1 ] = get_int_array_hash (hashes , i );
159159
160+ pfree (hashes );
161+
160162 return get_int_array_hash (final_hashes , 2 );
161163}
162164
@@ -224,6 +226,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
224226 clause_has_consts [i ] = (args != NULL && has_consts (* args ));
225227 i ++ ;
226228 }
229+ pfree (args_hash );
227230
228231 idx = argsort (clause_hashes , n , sizeof (* clause_hashes ), int_cmp );
229232 inverse_idx = inverse_permutation (idx , n );
@@ -234,6 +237,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
234237 sorted_clauses [inverse_idx [i ]] = clause_hashes [i ];
235238 i ++ ;
236239 }
240+ pfree (clause_hashes );
237241
238242 i = 0 ;
239243 foreach (lc , selectivities )
@@ -249,6 +253,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
249253 }
250254 i ++ ;
251255 }
256+ pfree (inverse_idx );
252257
253258 for (i = 0 ; i < n ;)
254259 {
@@ -272,6 +277,8 @@ get_fss_for_object(List *relsigns, List *clauselist,
272277 sizeof (* * features ), double_cmp );
273278 i = j ;
274279 }
280+ pfree (idx );
281+ pfree (clause_has_consts );
275282
276283 /*
277284 * Generate feature subspace hash.
@@ -281,6 +288,8 @@ get_fss_for_object(List *relsigns, List *clauselist,
281288 eclasses_hash = get_int_array_hash (eclass_hash , nargs );
282289 relations_hash = get_relations_hash (relsigns );
283290 fss_hash = get_fss_hash (clauses_hash , eclasses_hash , relations_hash );
291+ pfree (sorted_clauses );
292+ pfree (eclass_hash );
284293
285294 if (nfeatures != NULL )
286295 {
@@ -340,11 +349,17 @@ static int
340349get_node_hash (Node * node )
341350{
342351 char * str ;
352+ char * no_consts ;
353+ char * no_locations ;
343354 int hash ;
344355
345- str = remove_locations ( remove_consts ( nodeToString (node )) );
346- hash = get_str_hash (str );
356+ str = nodeToString (node );
357+ no_consts = remove_consts (str );
347358 pfree (str );
359+ no_locations = remove_locations (no_consts );
360+ pfree (no_consts );
361+ hash = get_str_hash (no_locations );
362+ pfree (no_locations );
348363 return hash ;
349364}
350365
@@ -467,6 +482,7 @@ get_relations_hash(List *relsigns)
467482
468483 result = DatumGetInt32 (hash_any ((const unsigned char * ) hashes ,
469484 nhashes * sizeof (uint32 )));
485+ pfree (hashes );
470486
471487 return result ;
472488}
@@ -479,9 +495,11 @@ static char *
479495remove_consts (const char * str )
480496{
481497 char * res ;
498+ char * tmp ;
482499
483- res = replace_patterns (str , "{CONST" , is_brace );
484- res = replace_patterns (res , ":stmt_len" , is_brace );
500+ tmp = replace_patterns (str , "{CONST" , is_brace );
501+ res = replace_patterns (tmp , ":stmt_len" , is_brace );
502+ pfree (tmp );
485503 return res ;
486504}
487505
@@ -683,6 +701,8 @@ get_eclasses(List *clauselist, int *nargs, int **args_hash, int **eclass_hash)
683701
684702 for (i = 0 ; i < * nargs ; ++ i )
685703 (* eclass_hash )[i ] = e_hashes [disjoint_set_get_parent (p , i )];
704+
705+ pfree (e_hashes );
686706}
687707
688708/*
0 commit comments