From e6a90040835ccfb32479f2c42f5baecaa72d9ec0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A4=9A=E5=8D=8E=E5=85=B4?= <15381158111@163.com> Date: Wed, 19 Jan 2022 11:37:57 +0900 Subject: [PATCH] Properly free all elements in a list HintStateDelete tried to free the elements of hstate->all_hints[] but actually it only freed part of them. Correct the code as it intended. Some other palloced blocks are being hanged under the struct but we don't bother trying to be perfect at cleaning up the whole struct since it will be freed up at query end. --- pg_hint_plan.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pg_hint_plan.c b/pg_hint_plan.c index 766aa2a..8534cea 100644 --- a/pg_hint_plan.c +++ b/pg_hint_plan.c @@ -1081,12 +1081,18 @@ HintStateDelete(HintState *hstate) if (hstate->hint_str) pfree(hstate->hint_str); - for (i = 0; i < hstate->num_hints[HINT_TYPE_SCAN_METHOD]; i++) + for (i = 0; i < hstate->nall_hints ; i++) hstate->all_hints[i]->delete_func(hstate->all_hints[i]); if (hstate->all_hints) pfree(hstate->all_hints); if (hstate->parent_index_infos) list_free(hstate->parent_index_infos); + + /* + * We have another few or dozen of palloced block in the struct, but don't + * bother completely clean up all of them since they will be cleaned-up at + * the end of this query. + */ } /* -- 2.11.0