From 5e7f187d93cf80fb4785748c2296790c3c08819b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Mon, 14 Oct 2024 15:31:54 +0200 Subject: [PATCH] scenechange: fix memory leak A reference to the last buffer(oldbuf) was kept leading to a memory leak on stop. Part-of: --- .../gst/videofilters/gstscenechange.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/videofilters/gstscenechange.c b/subprojects/gst-plugins-bad/gst/videofilters/gstscenechange.c index 93e761b8b0..970583fe6d 100644 --- a/subprojects/gst-plugins-bad/gst/videofilters/gstscenechange.c +++ b/subprojects/gst-plugins-bad/gst/videofilters/gstscenechange.c @@ -60,7 +60,7 @@ * terms of accuracy, schro's implementation has about 2-3 false positives * or false negatives per 100 scene changes. This implementation has * about 5 per 100. The threshold is tuned for minimum total false - * positives or negatives, on the assumption that the badness of a + * positives or negatives, on the assumption that the badness of a * false negative is the same as a false positive. * * This algorithm is pretty much at its limit for error rate. I @@ -92,6 +92,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_scene_change_debug_category); static GstFlowReturn gst_scene_change_transform_frame_ip (GstVideoFilter * filter, GstVideoFrame * frame); +static gboolean gst_scenechange_stop (GstBaseTransform * base); #undef TESTING #ifdef TESTING @@ -119,6 +120,7 @@ static void gst_scene_change_class_init (GstSceneChangeClass * klass) { GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_CLASS (klass); + GstBaseTransformClass *trans_class = GST_BASE_TRANSFORM_CLASS (klass); gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass), gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, @@ -135,6 +137,7 @@ gst_scene_change_class_init (GstSceneChangeClass * klass) video_filter_class->transform_frame_ip = GST_DEBUG_FUNCPTR (gst_scene_change_transform_frame_ip); + trans_class->stop = GST_DEBUG_FUNCPTR (gst_scenechange_stop); } static void @@ -142,7 +145,6 @@ gst_scene_change_init (GstSceneChange * scenechange) { } - static double get_frame_score (GstVideoFrame * f1, GstVideoFrame * f2) { @@ -259,10 +261,15 @@ gst_scene_change_transform_frame_ip (GstVideoFilter * filter, return GST_FLOW_OK; } +static gboolean +gst_scenechange_stop (GstBaseTransform * base) +{ + GstSceneChange *scenechange = GST_SCENE_CHANGE (base); + gst_clear_buffer (&scenechange->oldbuf); - - + return TRUE; +} #ifdef TESTING /* This is from ds's personal collection. No, you can't have it. */