summaryrefslogtreecommitdiff
path: root/media-video/ffmpeg/files/ffmpeg-6.1.1-memory-leak.patch
blob: d02522b3a3a431df6977e7debdfd6dab54089dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
https://bugs.gentoo.org/931059
https://ffmpeg.org//pipermail/ffmpeg-devel/2024-May/326569.html
https://git.videolan.org/?p=ffmpeg.git;a=commit;h=670c823406612697b394d4933e03d3e1a176474f
https://git.videolan.org/?p=ffmpeg.git;a=commit;h=1606aab99bd84f0040fb0fa6ccccb092941f01ec

From 670c823406612697b394d4933e03d3e1a176474f Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Fri, 27 Oct 2023 14:26:50 +0200
Subject: [PATCH] avfilter/buffersrc: switch to activate

Fixes OOM when caller keeps adding frames into filtergraph
that reached EOF by other means, for example EOF is signalled
by other filter in filtergraph or by buffersink.

(cherry picked from commit 84e400ae37b1e2849a3ead399ef86c808356cdd6)
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -36,6 +36,7 @@
 #include "audio.h"
 #include "avfilter.h"
 #include "buffersrc.h"
+#include "filters.h"
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
@@ -194,7 +195,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     if (!frame)
         return av_buffersrc_close(ctx, s->last_pts, flags);
     if (s->eof)
-        return AVERROR(EINVAL);
+        return AVERROR_EOF;
 
     s->last_pts = frame->pts + frame->duration;
 
@@ -484,21 +485,28 @@ static int config_props(AVFilterLink *link)
     return 0;
 }
 
-static int request_frame(AVFilterLink *link)
+static int activate(AVFilterContext *ctx)
 {
-    BufferSourceContext *c = link->src->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+    BufferSourceContext *c = ctx->priv;
 
-    if (c->eof)
-        return AVERROR_EOF;
+    if (!c->eof && ff_outlink_get_status(outlink)) {
+        c->eof = 1;
+        return 0;
+    }
+
+    if (c->eof) {
+        ff_outlink_set_status(outlink, AVERROR_EOF, c->last_pts);
+        return 0;
+    }
     c->nb_failed_requests++;
-    return AVERROR(EAGAIN);
+    return FFERROR_NOT_READY;
 }
 
 static const AVFilterPad avfilter_vsrc_buffer_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
-        .request_frame = request_frame,
         .config_props  = config_props,
     },
 };
@@ -507,7 +515,7 @@ const AVFilter ff_vsrc_buffer = {
     .name      = "buffer",
     .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them accessible to the filterchain."),
     .priv_size = sizeof(BufferSourceContext),
-
+    .activate  = activate,
     .init      = init_video,
     .uninit    = uninit,
 
@@ -521,7 +529,6 @@ static const AVFilterPad avfilter_asrc_abuffer_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_AUDIO,
-        .request_frame = request_frame,
         .config_props  = config_props,
     },
 };
@@ -530,7 +537,7 @@ const AVFilter ff_asrc_abuffer = {
     .name          = "abuffer",
     .description   = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them accessible to the filterchain."),
     .priv_size     = sizeof(BufferSourceContext),
-
+    .activate  = activate,
     .init      = init_audio,
     .uninit    = uninit,
 
-- 
2.30.2

From 1606aab99bd84f0040fb0fa6ccccb092941f01ec Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Fri, 1 Dec 2023 16:59:07 +0100
Subject: [PATCH] avfilter/avfilter: fix OOM case for default activate

Fixes OOM when caller keeps adding frames into filtergraph
that reached EOF by other means, for example EOF is signalled
by other filter in filtergraph or by buffersink.

(cherry picked from commit d9e41ead82263e96ebd14d4d88d6e7f858dd944c)
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -1167,6 +1167,16 @@ static int ff_filter_activate_default(AVFilterContext *filter)
 {
     unsigned i;
 
+    for (i = 0; i < filter->nb_outputs; i++) {
+        int ret = filter->outputs[i]->status_in;
+
+        if (ret) {
+            for (int j = 0; j < filter->nb_inputs; j++)
+                ff_inlink_set_status(filter->inputs[j], ret);
+            return 0;
+        }
+    }
+
     for (i = 0; i < filter->nb_inputs; i++) {
         if (samples_ready(filter->inputs[i], filter->inputs[i]->min_samples)) {
             return ff_filter_frame_to_filter(filter->inputs[i]);
-- 
2.30.2