[FFmpeg-devel] [PATCH 2/4] avfiltergraph: Properly handle memory allocation failure
Derek Buitenhuis
derek.buitenhuis at gmail.com
Tue Oct 22 22:33:57 CEST 2013
Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
---
libavfilter/avfiltergraph.c | 41 ++++++++++++++++++++++++++++++++---------
1 file changed, 32 insertions(+), 9 deletions(-)
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 2db2900..19e1dfd 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -392,6 +392,19 @@ static int can_merge_formats(AVFilterFormats *a_arg,
return 1;
a = clone_filter_formats(a_arg);
b = clone_filter_formats(b_arg);
+
+ if (!a || !b) {
+ if (a)
+ av_freep(&a->formats);
+ if (b)
+ av_freep(&b->formats);
+
+ av_freep(&a);
+ av_freep(&b);
+
+ return AVERROR(ENOMEM);
+ }
+
if (is_sample_rate) {
ret = ff_merge_samplerates(a, b);
} else {
@@ -456,17 +469,27 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
continue;
if (link->in_formats != link->out_formats
- && link->in_formats && link->out_formats)
- if (!can_merge_formats(link->in_formats, link->out_formats,
- link->type, 0))
- convert_needed = 1;
+ && link->in_formats && link->out_formats) {
+
+ ret = can_merge_formats(link->in_formats, link->out_formats,
+ link->type, 0);
+ if (ret < 0)
+ return ret;
+
+ convert_needed = !ret;
+ }
if (link->type == AVMEDIA_TYPE_AUDIO) {
if (link->in_samplerates != link->out_samplerates
- && link->in_samplerates && link->out_samplerates)
- if (!can_merge_formats(link->in_samplerates,
- link->out_samplerates,
- 0, 1))
- convert_needed = 1;
+ && link->in_samplerates && link->out_samplerates) {
+
+ ret = can_merge_formats(link->in_samplerates,
+ link->out_samplerates,
+ 0, 1);
+ if (ret < 0)
+ return ret;
+
+ convert_needed = !ret;
+ }
}
#define MERGE_DISPATCH(field, statement) \
--
1.8.4.rc3
More information about the ffmpeg-devel
mailing list