From ac5d5046c8ef4988b36734effe42a2fae8547ce1 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Mon, 18 Nov 2019 08:47:58 +0100 Subject: 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 --- libavcodec/cbs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libavcodec/cbs.h') diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index cdb777d111..9ca1fbd609 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -376,7 +376,8 @@ int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, * Insert a new unit into a fragment with the given data bitstream. * * If data_buf is not supplied then data must have been allocated with - * av_malloc() and will become owned by the unit after this call. + * av_malloc() and will on success become owned by the unit after this + * call or freed on error. */ int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, -- cgit v1.2.3