From b8e11e0a5292c81c06831b8a0543dbfca5346f89 Mon Sep 17 00:00:00 2001 From: Bradley Sepos Date: Wed, 10 Jan 2018 23:50:43 -0500 Subject: [PATCH] libhb: Plug memory leak in NLMeans. This reverts 0e072aa42e3affd6280447317375460753f9284b and implements a proper fix for some frames not being prefiltered correctly. Turns out it was an issue with an uninitialized variable. --- libhb/nlmeans.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libhb/nlmeans.c b/libhb/nlmeans.c index 2226ee919..e6f8f1767 100644 --- a/libhb/nlmeans.c +++ b/libhb/nlmeans.c @@ -97,6 +97,7 @@ typedef struct int h; int border; hb_lock_t *mutex; + int prefiltered; } BorderedPlane; typedef struct @@ -251,8 +252,9 @@ static void nlmeans_alloc(const uint8_t *src, dst->border = border; nlmeans_border(dst->mem, dst->w, dst->h, dst->border); - dst->mem_pre = dst->mem; - dst->image_pre = dst->image; + dst->mem_pre = dst->mem; + dst->image_pre = dst->image; + dst->prefiltered = 0; } @@ -585,6 +587,11 @@ static void nlmeans_prefilter(BorderedPlane *src, const int filter_type) { hb_lock(src->mutex); + if (src->prefiltered) + { + hb_unlock(src->mutex); + return; + } if (filter_type & NLMEANS_PREFILTER_MODE_MEAN3X3 || filter_type & NLMEANS_PREFILTER_MODE_MEAN5X5 || @@ -696,6 +703,7 @@ static void nlmeans_prefilter(BorderedPlane *src, nlmeans_border(mem_pre, w, h, border); } + src->prefiltered = 1; hb_unlock(src->mutex); } -- 2.40.0