[FFmpeg-devel] [PATCH] ffprobe: Fix memory leak

Derek Buitenhuis derek.buitenhuis at gmail.com
Fri Jun 21 16:36:55 EEST 2019


This packet was not necessarily unreferenced.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
---
 fftools/ffprobe.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 3becb6330e..52f24e7dfd 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2351,6 +2351,7 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile,
     int ret = 0, i = 0, frame_count = 0;
     int64_t start = -INT64_MAX, end = interval->end;
     int has_start = 0, has_end = interval->has_end && !interval->end_is_offset;
+    int needs_unref = 0;
 
     av_init_packet(&pkt);
 
@@ -2410,9 +2411,12 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile,
             }
 
             if (interval->end_is_offset && interval->duration_frames) {
-                if (frame_count >= interval->end)
+                if (frame_count >= interval->end) {
+                    needs_unref = 1;
                     break;
+                }
             } else if (has_end && *cur_ts != AV_NOPTS_VALUE && *cur_ts >= end) {
+                needs_unref = 1;
                 break;
             }
 
@@ -2429,6 +2433,10 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile,
         }
         av_packet_unref(&pkt);
     }
+
+    if (needs_unref)
+        av_packet_unref(&pkt);
+
     av_init_packet(&pkt);
     pkt.data = NULL;
     pkt.size = 0;
-- 
2.20.1



More information about the ffmpeg-devel mailing list