diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2019-09-12 00:18:29 +0200 |
---|---|---|
committer | Mark Thompson <sw@jkqxz.net> | 2019-09-24 15:54:31 +0100 |
commit | f83ac5fd793f6464020777da6802803048b97fc6 (patch) | |
tree | 3d4b4341e5b90653d7b29ab11afaea0c0da33f6d /libavcodec/cbs_h2645.c | |
parent | 8c7d5fcfc32d65951039ab2bb78947a41bdd96c4 (diff) | |
download | ffmpeg-f83ac5fd793f6464020777da6802803048b97fc6.tar.gz |
avcodec/cbs_h264: Automatically free SEI payload on error
If adding an SEI message to an access unit fails, said SEI message was
not touched, so that the caller had to free any data associated with it
that might need to be freed. But given that ff_cbs_h264_add_sei_message
can simply call cbs_h264_free_sei_payload, one can easily free
the content of the SEI payload.
This fixes a memleak when inserting a user data unregistered string for
h264_metadata fails.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/cbs_h2645.c')
-rw-r--r-- | libavcodec/cbs_h2645.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 8da8421e47..2dc261f7a5 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1586,7 +1586,7 @@ const CodedBitstreamType ff_cbs_type_h265 = { int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, - const H264RawSEIPayload *payload) + H264RawSEIPayload *payload) { H264RawSEI *sei = NULL; int err, i; @@ -1608,8 +1608,10 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, AVBufferRef *sei_ref; sei = av_mallocz(sizeof(*sei)); - if (!sei) - return AVERROR(ENOMEM); + if (!sei) { + err = AVERROR(ENOMEM); + goto fail; + } sei->nal_unit_header.nal_unit_type = H264_NAL_SEI; sei->nal_unit_header.nal_ref_idc = 0; @@ -1618,7 +1620,8 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, &cbs_h264_free_sei, NULL, 0); if (!sei_ref) { av_freep(&sei); - return AVERROR(ENOMEM); + err = AVERROR(ENOMEM); + goto fail; } for (i = 0; i < au->nb_units; i++) { @@ -1631,13 +1634,16 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, sei, sei_ref); av_buffer_unref(&sei_ref); if (err < 0) - return err; + goto fail; } memcpy(&sei->payload[sei->payload_count], payload, sizeof(*payload)); ++sei->payload_count; return 0; +fail: + cbs_h264_free_sei_payload(payload); + return err; } void ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx, |