1212 *
1313 *******************************************************************************
1414 *
15- * Copyright (c) 2016-2022 , Postgres Professional
15+ * Copyright (c) 2016-2023 , Postgres Professional
1616 *
1717 * IDENTIFICATION
1818 * aqo/hash.c
@@ -175,6 +175,8 @@ get_grouped_exprs_hash(int child_fss, List *group_exprs)
175175 final_hashes [0 ] = child_fss ;
176176 final_hashes [1 ] = get_int_array_hash (hashes , i );
177177
178+ pfree (hashes );
179+
178180 return get_int_array_hash (final_hashes , 2 );
179181}
180182
@@ -242,6 +244,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
242244 clause_has_consts [i ] = (args != NULL && has_consts (* args ));
243245 i ++ ;
244246 }
247+ pfree (args_hash );
245248
246249 idx = argsort (clause_hashes , n , sizeof (* clause_hashes ), int_cmp );
247250 inverse_idx = inverse_permutation (idx , n );
@@ -252,6 +255,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
252255 sorted_clauses [inverse_idx [i ]] = clause_hashes [i ];
253256 i ++ ;
254257 }
258+ pfree (clause_hashes );
255259
256260 i = 0 ;
257261 foreach (lc , selectivities )
@@ -267,6 +271,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
267271 }
268272 i ++ ;
269273 }
274+ pfree (inverse_idx );
270275
271276 for (i = 0 ; i < n ;)
272277 {
@@ -290,6 +295,8 @@ get_fss_for_object(List *relsigns, List *clauselist,
290295 sizeof (* * features ), double_cmp );
291296 i = j ;
292297 }
298+ pfree (idx );
299+ pfree (clause_has_consts );
293300
294301 /*
295302 * Generate feature subspace hash.
@@ -299,6 +306,8 @@ get_fss_for_object(List *relsigns, List *clauselist,
299306 eclasses_hash = get_int_array_hash (eclass_hash , nargs );
300307 relations_hash = get_relations_hash (relsigns );
301308 fss_hash = get_fss_hash (clauses_hash , eclasses_hash , relations_hash );
309+ pfree (sorted_clauses );
310+ pfree (eclass_hash );
302311
303312 if (nfeatures != NULL )
304313 {
@@ -358,11 +367,17 @@ static int
358367get_node_hash (Node * node )
359368{
360369 char * str ;
370+ char * no_consts ;
371+ char * no_locations ;
361372 int hash ;
362373
363- str = remove_locations ( remove_consts ( nodeToString (node )) );
364- hash = get_str_hash (str );
374+ str = nodeToString (node );
375+ no_consts = remove_consts (str );
365376 pfree (str );
377+ no_locations = remove_locations (no_consts );
378+ pfree (no_consts );
379+ hash = get_str_hash (no_locations );
380+ pfree (no_locations );
366381 return hash ;
367382}
368383
@@ -485,6 +500,7 @@ get_relations_hash(List *relsigns)
485500
486501 result = DatumGetInt32 (hash_any ((const unsigned char * ) hashes ,
487502 nhashes * sizeof (uint32 )));
503+ pfree (hashes );
488504
489505 return result ;
490506}
@@ -497,9 +513,11 @@ static char *
497513remove_consts (const char * str )
498514{
499515 char * res ;
516+ char * tmp ;
500517
501- res = replace_patterns (str , "{CONST" , is_brace );
502- res = replace_patterns (res , ":stmt_len" , is_brace );
518+ tmp = replace_patterns (str , "{CONST" , is_brace );
519+ res = replace_patterns (tmp , ":stmt_len" , is_brace );
520+ pfree (tmp );
503521 return res ;
504522}
505523
@@ -701,6 +719,8 @@ get_eclasses(List *clauselist, int *nargs, int **args_hash, int **eclass_hash)
701719
702720 for (i = 0 ; i < * nargs ; ++ i )
703721 (* eclass_hash )[i ] = e_hashes [disjoint_set_get_parent (p , i )];
722+
723+ pfree (e_hashes );
704724}
705725
706726/*
0 commit comments