[FFmpeg-devel] [PATCH 2/2] avcodec/avpacket: fix leaks on side data copying failure
James Almer
jamrial at gmail.com
Sat Sep 23 21:47:00 EEST 2017
On 9/21/2017 7:04 PM, James Almer wrote:
> pkt->side_data_elems being set at the very end of the process will leak memory
> if some side data elements were already copied before an error ocurrs.
>
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
> libavcodec/avpacket.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index a68e2501ad..13e830b781 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -230,17 +230,20 @@ int av_copy_packet_side_data(AVPacket *pkt, const AVPacket *src)
>
> if (src->side_data_elems) {
> int i;
> +
> + pkt->side_data_elems = 0;
> pkt->side_data = av_mallocz_array(src->side_data_elems, sizeof(*src->side_data));
> if (!pkt->side_data)
> goto failed_alloc;
> +
> for (i = 0; i < src->side_data_elems; i++) {
> DUP_DATA(pkt->side_data[i].data, src->side_data[i].data,
> src->side_data[i].size, 1, ALLOC_MALLOC);
> pkt->side_data[i].size = src->side_data[i].size;
> pkt->side_data[i].type = src->side_data[i].type;
> + pkt->side_data_elems++;
> }
> }
> - pkt->side_data_elems = src->side_data_elems;
> return 0;
>
> failed_alloc:
>
Dropped alongside patch 1/2.
More information about the ffmpeg-devel
mailing list