From e5da64bb8b631130fb2b2859d0b7034a14a46ce0 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 17 Jan 2017 19:03:46 +0000 Subject: [PATCH] [Fix] Fix memory leak in safe ucl iterators --- contrib/libucl/ucl_util.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/contrib/libucl/ucl_util.c b/contrib/libucl/ucl_util.c index 6691c8546..a26d4748d 100644 --- a/contrib/libucl/ucl_util.c +++ b/contrib/libucl/ucl_util.c @@ -2501,6 +2501,11 @@ ucl_object_iterate_full (ucl_object_iter_t it, enum ucl_iterate_type type) if (ret == NULL && (type & UCL_ITERATE_IMPLICIT)) { /* Need to switch to another implicit object in chain */ rit->impl_it = rit->impl_it->next; + + if (rit->expl_it != NULL) { + UCL_FREE (sizeof (*rit->expl_it), rit->expl_it); + } + rit->expl_it = NULL; return ucl_object_iterate_safe (it, type); } @@ -2509,6 +2514,7 @@ ucl_object_iterate_full (ucl_object_iter_t it, enum ucl_iterate_type type) /* Just iterate over the implicit array */ ret = rit->impl_it; rit->impl_it = rit->impl_it->next; + if (type & UCL_ITERATE_EXPLICIT) { /* We flatten objects if need to expand values */ if (ret->type == UCL_OBJECT || ret->type == UCL_ARRAY) { @@ -2527,6 +2533,10 @@ ucl_object_iterate_free (ucl_object_iter_t it) UCL_SAFE_ITER_CHECK (rit); + if (rit->expl_it != NULL) { + UCL_FREE (sizeof (*rit->expl_it), rit->expl_it); + } + UCL_FREE (sizeof (*rit), it); } -- 2.39.5