Fix memory leak in HitQueue HitQueue would leak a FieldType if the last SortRule was of type FIELD. This wasn't discovered by our test suite because we always break ties by DOC_ID.
Thanks to Serkan Mulayim for the report. Fixes LUCY-315. Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/764a8894 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/764a8894 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/764a8894 Branch: refs/heads/0.6 Commit: 764a889446fc7dcd95b6dc8ccd7f93b20acf44de Parents: 7467be5 Author: Nick Wellnhofer <[email protected]> Authored: Wed Oct 19 13:29:58 2016 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Wed Oct 19 13:50:16 2016 +0200 ---------------------------------------------------------------------- core/Lucy/Search/HitQueue.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/764a8894/core/Lucy/Search/HitQueue.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Search/HitQueue.c b/core/Lucy/Search/HitQueue.c index 94d4101..861c177 100644 --- a/core/Lucy/Search/HitQueue.c +++ b/core/Lucy/Search/HitQueue.c @@ -108,13 +108,15 @@ HitQ_init(HitQueue *self, Schema *schema, SortSpec *sort_spec, void HitQ_Destroy_IMP(HitQueue *self) { HitQueueIVARS *const ivars = HitQ_IVARS(self); - FieldType **types = ivars->field_types; - FieldType **const limit = types + ivars->num_actions - 1; - for (; types < limit; types++) { - if (types) { DECREF(*types); } + if (ivars->field_types) { + FieldType **types = ivars->field_types; + FieldType **const limit = types + ivars->num_actions; + for (; types < limit; types++) { + DECREF(*types); + } + FREEMEM(ivars->field_types); } FREEMEM(ivars->actions); - FREEMEM(ivars->field_types); SUPER_DESTROY(self, HITQUEUE); }
