Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-11-18 10:47:58 +0300
committerMark Thompson <sw@jkqxz.net>2020-02-10 01:23:29 +0300
commitac5d5046c8ef4988b36734effe42a2fae8547ce1 (patch)
treeda35e39aebdf8cf76f08ab4df6797e84a0c433fa /libavcodec/cbs_jpeg.c
parent1e6cef686183288a50eb4e45265a3a7f7582b1b5 (diff)
avcodec/cbs: Fix potential double-free when adding unit fails
ff_cbs_insert_unit_data() has two modes of operation: It can insert a unit with a newly created reference to an already existing AVBuffer; or it can take a buffer and create an AVBuffer for it. Said buffer will then become owned by the unit lateron. A potential memleak/double-free exists in the second case, because if creating the AVBuffer fails, the function immediately returns, but when it fails lateron, the supplied buffer will be freed. The caller has no way to distinguish between these two outcomes. The only such caller (cbs_jpeg_split_fragment() in cbs_jpeg.c) opted for a potential double-free. This commit changes this by explicitly stating that a non-refcounted buffer will be freed on error. The aforementioned caller has been brought in line with this. Fixes CID 1452623. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/cbs_jpeg.c')
-rw-r--r--libavcodec/cbs_jpeg.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
index b189cbd9b7..b52e5c5823 100644
--- a/libavcodec/cbs_jpeg.c
+++ b/libavcodec/cbs_jpeg.c
@@ -225,11 +225,8 @@ static int cbs_jpeg_split_fragment(CodedBitstreamContext *ctx,
err = ff_cbs_insert_unit_data(ctx, frag, unit, marker,
data, data_size, data_ref);
- if (err < 0) {
- if (!data_ref)
- av_freep(&data);
+ if (err < 0)
return err;
- }
if (next_marker == -1)
break;