* [FFmpeg-devel] [PATCH] doc/examples/extract_mvs: fix memory leak in codec context initialization
2026-01-05 1:11 [FFmpeg-devel] [PATCH] doc/examples/avio_http_serve_files: prevent zombie processes 0xBat via ffmpeg-devel
@ 2026-01-05 1:11 ` 0xBat via ffmpeg-devel
2026-01-09 2:20 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/filter_audio: fix memory leak and duration overflow 0xBat via ffmpeg-devel
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: 0xBat via ffmpeg-devel @ 2026-01-05 1:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 0xBat
Ensure the allocated AVCodecContext is properly freed if avcodec_parameters_to_context fails.
Signed-off-by: 0xBat <monsterbat02@gmail.com>
---
| 1 +
1 file changed, 1 insertion(+)
--git a/doc/examples/extract_mvs.c b/doc/examples/extract_mvs.c
index 5603064d72..b5ed2c5549 100644
--- a/doc/examples/extract_mvs.c
+++ b/doc/examples/extract_mvs.c
@@ -109,6 +109,7 @@ static int open_codec_context(AVFormatContext *fmt_ctx, enum AVMediaType type)
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);
return ret;
}
--
2.52.0.windows.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] 11+ messages in thread* [FFmpeg-devel] Re: [PATCH] doc/examples/extract_mvs: fix memory leak in codec context initialization
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/extract_mvs: fix memory leak in codec context initialization 0xBat via ffmpeg-devel
@ 2026-01-09 2:20 ` Michael Niedermayer via ffmpeg-devel
0 siblings, 0 replies; 11+ messages in thread
From: Michael Niedermayer via ffmpeg-devel @ 2026-01-09 2:20 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Michael Niedermayer
[-- Attachment #1.1: Type: text/plain, Size: 1155 bytes --]
Hi 0xBat
On Mon, Jan 05, 2026 at 02:11:42AM +0100, 0xBat via ffmpeg-devel wrote:
> Ensure the allocated AVCodecContext is properly freed if avcodec_parameters_to_context fails.
>
> Signed-off-by: 0xBat <monsterbat02@gmail.com>
> ---
> doc/examples/extract_mvs.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/doc/examples/extract_mvs.c b/doc/examples/extract_mvs.c
> index 5603064d72..b5ed2c5549 100644
> --- a/doc/examples/extract_mvs.c
> +++ b/doc/examples/extract_mvs.c
> @@ -109,6 +109,7 @@ static int open_codec_context(AVFormatContext *fmt_ctx, enum AVMediaType type)
> 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);
> return ret;
> }
will apply
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [FFmpeg-devel] [PATCH] doc/examples/filter_audio: fix memory leak and duration overflow
2026-01-05 1:11 [FFmpeg-devel] [PATCH] doc/examples/avio_http_serve_files: prevent zombie processes 0xBat via ffmpeg-devel
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/extract_mvs: fix memory leak in codec context initialization 0xBat via ffmpeg-devel
@ 2026-01-05 1:11 ` 0xBat via ffmpeg-devel
2026-01-09 2:05 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/hw_decode: fix memory leak in codec context initialization 0xBat via ffmpeg-devel
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: 0xBat via ffmpeg-devel @ 2026-01-05 1:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 0xBat
Ensure filter_graph is freed on error and validate duration input to prevent integer overflow.
Signed-off-by: 0xBat <monsterbat02@gmail.com>
---
doc/examples/filter_audio.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/doc/examples/filter_audio.c b/doc/examples/filter_audio.c
index ad77bf1f89..bb88f4571b 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);
return AVERROR_FILTER_NOT_FOUND;
}
@@ -279,6 +280,10 @@ int main(int argc, char *argv[])
}
duration = atof(argv[1]);
+ 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]);
--
2.52.0.windows.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] 11+ messages in thread* [FFmpeg-devel] Re: [PATCH] doc/examples/filter_audio: fix memory leak and duration overflow
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/filter_audio: fix memory leak and duration overflow 0xBat via ffmpeg-devel
@ 2026-01-09 2:05 ` Michael Niedermayer via ffmpeg-devel
0 siblings, 0 replies; 11+ messages in thread
From: Michael Niedermayer via ffmpeg-devel @ 2026-01-09 2:05 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Michael Niedermayer
[-- Attachment #1.1: Type: text/plain, Size: 1702 bytes --]
Hi 0xBat
On Mon, Jan 05, 2026 at 02:11:43AM +0100, 0xBat via ffmpeg-devel wrote:
> Ensure filter_graph is freed on error and validate duration input to prevent integer overflow.
if you have t o write "and" in the commit message, thats generally a sign
that there are 2 independant changes that would be clearer in 2 commits
>
> Signed-off-by: 0xBat <monsterbat02@gmail.com>
> ---
> doc/examples/filter_audio.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/doc/examples/filter_audio.c b/doc/examples/filter_audio.c
> index ad77bf1f89..bb88f4571b 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);
> return AVERROR_FILTER_NOT_FOUND;
> }
>
> @@ -279,6 +280,10 @@ int main(int argc, char *argv[])
> }
>
> duration = atof(argv[1]);
> + if (duration > (double)2147483647 / INPUT_SAMPLERATE) {
hardcoded arbitrary number instead of the named identifer used below
> + fprintf(stderr, "Duration too long\n");
> + return 1;
> + }
> nb_frames = duration * INPUT_SAMPLERATE / FRAME_SIZE;
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [FFmpeg-devel] [PATCH] doc/examples/hw_decode: fix memory leak in codec context initialization
2026-01-05 1:11 [FFmpeg-devel] [PATCH] doc/examples/avio_http_serve_files: prevent zombie processes 0xBat via ffmpeg-devel
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/extract_mvs: fix memory leak in codec context initialization 0xBat via ffmpeg-devel
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/filter_audio: fix memory leak and duration overflow 0xBat via ffmpeg-devel
@ 2026-01-05 1:11 ` 0xBat via ffmpeg-devel
2026-01-09 2:21 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/qsv_transcode: check for allocation failure 0xBat via ffmpeg-devel
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/transcode: fix memory leak in codec context initialization 0xBat via ffmpeg-devel
4 siblings, 1 reply; 11+ messages in thread
From: 0xBat via ffmpeg-devel @ 2026-01-05 1:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 0xBat
Properly free decoder_ctx on failure to prevent a memory leak during initialization.
Signed-off-by: 0xBat <monsterbat02@gmail.com>
---
doc/examples/hw_decode.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/doc/examples/hw_decode.c b/doc/examples/hw_decode.c
index ac4e445505..ce18814760 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)
+ if (avcodec_parameters_to_context(decoder_ctx, video->codecpar) < 0) {
+ avcodec_free_context(&decoder_ctx);
return -1;
+ }
decoder_ctx->get_format = get_hw_format;
--
2.52.0.windows.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] 11+ messages in thread* [FFmpeg-devel] Re: [PATCH] doc/examples/hw_decode: fix memory leak in codec context initialization
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/hw_decode: fix memory leak in codec context initialization 0xBat via ffmpeg-devel
@ 2026-01-09 2:21 ` Michael Niedermayer via ffmpeg-devel
0 siblings, 0 replies; 11+ messages in thread
From: Michael Niedermayer via ffmpeg-devel @ 2026-01-09 2:21 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Michael Niedermayer
[-- Attachment #1.1: Type: text/plain, Size: 539 bytes --]
Hi 0xBat
On Mon, Jan 05, 2026 at 02:11:44AM +0100, 0xBat via ffmpeg-devel wrote:
> Properly free decoder_ctx on failure to prevent a memory leak during initialization.
>
> Signed-off-by: 0xBat <monsterbat02@gmail.com>
> ---
> doc/examples/hw_decode.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
will apply
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [FFmpeg-devel] [PATCH] doc/examples/qsv_transcode: check for allocation failure
2026-01-05 1:11 [FFmpeg-devel] [PATCH] doc/examples/avio_http_serve_files: prevent zombie processes 0xBat via ffmpeg-devel
` (2 preceding siblings ...)
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/hw_decode: fix memory leak in codec context initialization 0xBat via ffmpeg-devel
@ 2026-01-05 1:11 ` 0xBat via ffmpeg-devel
2026-01-09 2:22 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/transcode: fix memory leak in codec context initialization 0xBat via ffmpeg-devel
4 siblings, 1 reply; 11+ messages in thread
From: 0xBat via ffmpeg-devel @ 2026-01-05 1:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 0xBat
Validate return value of av_malloc for dynamic_setting to avoid null pointer dereference.
Signed-off-by: 0xBat <monsterbat02@gmail.com>
---
doc/examples/qsv_transcode.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/doc/examples/qsv_transcode.c b/doc/examples/qsv_transcode.c
index 13b4933041..c3f507e8e6 100644
--- a/doc/examples/qsv_transcode.c
+++ b/doc/examples/qsv_transcode.c
@@ -351,6 +351,10 @@ int main(int argc, char **argv)
}
setting_number = (argc - 5) / 2;
dynamic_setting = av_malloc(setting_number * sizeof(*dynamic_setting));
+ 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]);
--
2.52.0.windows.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] 11+ messages in thread* [FFmpeg-devel] Re: [PATCH] doc/examples/qsv_transcode: check for allocation failure
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/qsv_transcode: check for allocation failure 0xBat via ffmpeg-devel
@ 2026-01-09 2:22 ` Michael Niedermayer via ffmpeg-devel
0 siblings, 0 replies; 11+ messages in thread
From: Michael Niedermayer via ffmpeg-devel @ 2026-01-09 2:22 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Michael Niedermayer
[-- Attachment #1.1: Type: text/plain, Size: 1088 bytes --]
Hi 0xBat
On Mon, Jan 05, 2026 at 02:11:45AM +0100, 0xBat via ffmpeg-devel wrote:
> Validate return value of av_malloc for dynamic_setting to avoid null pointer dereference.
>
> Signed-off-by: 0xBat <monsterbat02@gmail.com>
> ---
> doc/examples/qsv_transcode.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/doc/examples/qsv_transcode.c b/doc/examples/qsv_transcode.c
> index 13b4933041..c3f507e8e6 100644
> --- a/doc/examples/qsv_transcode.c
> +++ b/doc/examples/qsv_transcode.c
> @@ -351,6 +351,10 @@ int main(int argc, char **argv)
> }
> setting_number = (argc - 5) / 2;
> dynamic_setting = av_malloc(setting_number * sizeof(*dynamic_setting));
> + if (!dynamic_setting) {
> + ret = AVERROR(ENOMEM);
> + goto end;
> + }
will apply
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Many things microsoft did are stupid, but not doing something just because
microsoft did it is even more stupid. If everything ms did were stupid they
would be bankrupt already.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [FFmpeg-devel] [PATCH] doc/examples/transcode: fix memory leak in codec context initialization
2026-01-05 1:11 [FFmpeg-devel] [PATCH] doc/examples/avio_http_serve_files: prevent zombie processes 0xBat via ffmpeg-devel
` (3 preceding siblings ...)
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/qsv_transcode: check for allocation failure 0xBat via ffmpeg-devel
@ 2026-01-05 1:11 ` 0xBat via ffmpeg-devel
2026-01-09 1:54 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
4 siblings, 1 reply; 11+ messages in thread
From: 0xBat via ffmpeg-devel @ 2026-01-05 1:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 0xBat
Call avcodec_free_context to release memory if parameters cannot be copied to the context.
Signed-off-by: 0xBat <monsterbat02@gmail.com>
---
doc/examples/transcode.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 1dc1b50502..2bbe091b94 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -94,9 +94,9 @@ static int open_input_file(const char *filename)
}
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;
+ 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);
+ return ret;
}
/* Inform the decoder about the timebase for the packet timestamps.
--
2.52.0.windows.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] 11+ messages in thread* [FFmpeg-devel] Re: [PATCH] doc/examples/transcode: fix memory leak in codec context initialization
2026-01-05 1:11 ` [FFmpeg-devel] [PATCH] doc/examples/transcode: fix memory leak in codec context initialization 0xBat via ffmpeg-devel
@ 2026-01-09 1:54 ` Michael Niedermayer via ffmpeg-devel
0 siblings, 0 replies; 11+ messages in thread
From: Michael Niedermayer via ffmpeg-devel @ 2026-01-09 1:54 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Michael Niedermayer
[-- Attachment #1.1: Type: text/plain, Size: 1441 bytes --]
On Mon, Jan 05, 2026 at 02:11:46AM +0100, 0xBat via ffmpeg-devel wrote:
> Call avcodec_free_context to release memory if parameters cannot be copied to the context.
>
> Signed-off-by: 0xBat <monsterbat02@gmail.com>
> ---
> doc/examples/transcode.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
> index 1dc1b50502..2bbe091b94 100644
> --- a/doc/examples/transcode.c
> +++ b/doc/examples/transcode.c
> @@ -94,9 +94,9 @@ static int open_input_file(const char *filename)
> }
> 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;
> + 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);
> + return ret;
> }
Does the indention look correct to you ?
Also can you explain what you are trying to do with the av_log() change here ?
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: 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
^ permalink raw reply [flat|nested] 11+ messages in thread