Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Baptiste Bd via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Baptiste Bd <monsterbat02@gmail.com>
Subject: [FFmpeg-devel] [PATCH] examples: fix memory leaks, zombie processes and integer overflows
Date: Sat, 3 Jan 2026 19:29:20 +0100
Message-ID: <CABgBe0rfbNyMJ36THLmqOyVHJ+J+vxJfdCXND8DMV=3qRDDa5A@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 5408 bytes --]

>From 78bb1086f99b6ba234a9874246feb15360c8496c Mon Sep 17 00:00:00 2001
From: OxBat <monsterbat02@gmail.com>
Date: Sat, 3 Jan 2026 19:23:35 +0100
Subject: [PATCH] examples: fix memory leaks, zombie processes and integer
 overflows

---
 doc/examples/avio_http_serve_files.c |  2 ++
 doc/examples/extract_mvs.c           |  3 ++-
 doc/examples/filter_audio.c          |  6 ++++++
 doc/examples/hw_decode.c             |  6 ++++--
 doc/examples/qsv_transcode.c         |  5 +++++
 doc/examples/transcode.c             | 14 ++++++++------
 6 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/doc/examples/avio_http_serve_files.c
b/doc/examples/avio_http_serve_files.c
index 2aae3870c2..9aaf4b273b 100644
--- a/doc/examples/avio_http_serve_files.c
+++ b/doc/examples/avio_http_serve_files.c
@@ -31,6 +31,7 @@
 #include <libavformat/avformat.h>
 #include <libavutil/opt.h>
 #include <unistd.h>
+#include <signal.h>  /* NEW */

 static void process_client(AVIOContext *client, const char *in_uri)
 {
@@ -103,6 +104,7 @@ int main(int argc, char **argv)
     const char *in_uri, *out_uri;
     int ret, pid;
     av_log_set_level(AV_LOG_TRACE);
+    signal(SIGCHLD, SIG_IGN); /* PATCH: Prevent zombie processes */
     if (argc < 3) {
         printf("usage: %s input http://hostname[:port]\n"
                "API example program to serve http to multiple clients.\n"
diff --git a/doc/examples/extract_mvs.c b/doc/examples/extract_mvs.c
index 5603064d72..3052473e81 100644
--- a/doc/examples/extract_mvs.c
+++ b/doc/examples/extract_mvs.c
@@ -105,10 +105,11 @@ static int open_codec_context(AVFormatContext
*fmt_ctx, enum AVMediaType type)
             fprintf(stderr, "Failed to allocate codec\n");
             return AVERROR(EINVAL);
         }
-
+        /* PATCH: Memory leak*/
         ret = avcodec_parameters_to_context(dec_ctx, st->codecpar);
         if (ret < 0) {
             fprintf(stderr, "Failed to copy codec parameters to codec
context\n");
+            avcodec_free_context(&dec_ctx); /* PATCH: Fix leak */
             return ret;
         }

diff --git a/doc/examples/filter_audio.c b/doc/examples/filter_audio.c
index ad77bf1f89..c4673bddef 100644
--- a/doc/examples/filter_audio.c
+++ b/doc/examples/filter_audio.c
@@ -88,6 +88,7 @@ static int init_filter_graph(AVFilterGraph **graph,
AVFilterContext **src,
     abuffer = avfilter_get_by_name("abuffer");
     if (!abuffer) {
         fprintf(stderr, "Could not find the abuffer filter.\n");
+        avfilter_graph_free(&filter_graph); /* PATCH: Fix leak */
         return AVERROR_FILTER_NOT_FOUND;
     }

@@ -279,6 +280,11 @@ int main(int argc, char *argv[])
     }

     duration  = atof(argv[1]);
+/* PATCH: Check for integer overflow */
+    if (duration > (double)2147483647 / INPUT_SAMPLERATE) {
+    fprintf(stderr, "Duration too long\n");
+    return 1;
+    }
     nb_frames = duration * INPUT_SAMPLERATE / FRAME_SIZE;
     if (nb_frames <= 0) {
         fprintf(stderr, "Invalid duration: %s\n", argv[1]);
diff --git a/doc/examples/hw_decode.c b/doc/examples/hw_decode.c
index ac4e445505..caef3e93e3 100644
--- a/doc/examples/hw_decode.c
+++ b/doc/examples/hw_decode.c
@@ -215,8 +215,10 @@ int main(int argc, char *argv[])
         return AVERROR(ENOMEM);

     video = input_ctx->streams[video_stream];
-    if (avcodec_parameters_to_context(decoder_ctx, video->codecpar) < 0)
-        return -1;
+    if (avcodec_parameters_to_context(decoder_ctx, video->codecpar) < 0) {
+    avcodec_free_context(&decoder_ctx); /* PATCH: Fix leak */
+    return -1;
+}

     decoder_ctx->get_format  = get_hw_format;

diff --git a/doc/examples/qsv_transcode.c b/doc/examples/qsv_transcode.c
index 13b4933041..b780a65c79 100644
--- a/doc/examples/qsv_transcode.c
+++ b/doc/examples/qsv_transcode.c
@@ -351,6 +351,11 @@ int main(int argc, char **argv)
     }
     setting_number = (argc - 5) / 2;
     dynamic_setting = av_malloc(setting_number * sizeof(*dynamic_setting));
+    /* PATCH: Check allocation */
+    if (!dynamic_setting) {
+        ret = AVERROR(ENOMEM);
+        goto end;
+    }
     current_setting_number = 0;
     for (int i = 0; i < setting_number; i++) {
         dynamic_setting[i].frame_number = atoi(argv[i*2 + 5]);
diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 1dc1b50502..6dcacc1d4f 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -92,12 +92,14 @@ static int open_input_file(const char *filename)
             av_log(NULL, AV_LOG_ERROR, "Failed to allocate the decoder
context for stream #%u\n", i);
             return AVERROR(ENOMEM);
         }
-        ret = avcodec_parameters_to_context(codec_ctx, stream->codecpar);
-        if (ret < 0) {
-            av_log(NULL, AV_LOG_ERROR, "Failed to copy decoder parameters
to input decoder context "
-                   "for stream #%u\n", i);
-            return ret;
-        }
+    /* PATCH: Memory leak - Input Decoder */
+    ret = avcodec_parameters_to_context(codec_ctx, stream->codecpar);
+    if (ret < 0) {
+        av_log(NULL, AV_LOG_ERROR, "Failed to copy decoder parameters to
input decoder context "
+           "for stream #%u\n", i);
+        avcodec_free_context(&codec_ctx); /* PATCH: Fix leak */
+        return ret;
+    }

         /* Inform the decoder about the timebase for the packet timestamps.
          * This is highly recommended, but not mandatory. */
-- 
2.52.0.windows.1

[-- Attachment #2: 0001-examples-fix-memory-leaks-zombie-processes-and-integ.patch --]
[-- Type: application/octet-stream, Size: 5416 bytes --]

[-- Attachment #3: Type: text/plain, Size: 163 bytes --]

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2026-01-06  2:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABgBe0rfbNyMJ36THLmqOyVHJ+J+vxJfdCXND8DMV=3qRDDa5A@mail.gmail.com' \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=monsterbat02@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git