]> granicus.if.org Git - handbrake/commitdiff
libhb: Plug memory leak in NLMeans.
authorBradley Sepos <bradley@bradleysepos.com>
Thu, 11 Jan 2018 04:50:43 +0000 (23:50 -0500)
committerBradley Sepos <bradley@bradleysepos.com>
Thu, 11 Jan 2018 04:51:03 +0000 (23:51 -0500)
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

index 2226ee919f4b56c483c7e4cf8a399a2a255a93ec..e6f8f1767ea17f348500a6b11dbf39ee963f6380 100644 (file)
@@ -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);
 }