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/62cdcf93 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/62cdcf93 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/62cdcf93 Branch: refs/heads/master Commit: 62cdcf930dc871fb95b5c99fc86e93afe7a3e344 Parents: 87ea1b4 Author: Nick Wellnhofer <[email protected]> Authored: Wed Oct 19 13:29:58 2016 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Wed Oct 19 13:48:56 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/62cdcf93/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); }
