From patchwork Fri Oct 25 09:11:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15949 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9F191449DC1 for ; Fri, 25 Oct 2019 12:12:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B79268B419; Fri, 25 Oct 2019 12:12:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E535768B3E5 for ; Fri, 25 Oct 2019 12:12:24 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id a11so1421320wra.6 for ; Fri, 25 Oct 2019 02:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dvq2ykgdUrc9XM1PZS5ixeCzVghoCMdgo8lrnJ3BtPY=; b=O1XCLmII3tq0ljcRclsnCUWcibGVbmNpJ+V1YaqGoSQpnJjrPhYXWiSBaoiIRVlMKg f6Wb+8h7i1V8x7NouZMM9mG00HPedeYUtdLMDQpl+97+V6K6rq1qf/wb4R/cGfrlYEAv L+pmFmec6d+537/wk5fWEA9oT39kQlViMS9t9wXu92OS831vYx3/oUzQmDt0omheqKAv LdCNxIk+mVPRnBCGXVPHb3zm6JJyBch44AYFDNgSFWnWRuETOSzvtlsTxyAuAfgbeUsS YC98K1+0V0cmIDpf7PXBRkXK5+C7rRp7rXgKb3Nso7NcGe1zI8wklBI5s94p+6aPRPMG oBPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dvq2ykgdUrc9XM1PZS5ixeCzVghoCMdgo8lrnJ3BtPY=; b=hnV+XayAj5qJKIbpfDhyOAmAz5sTKQ25xP/lRQqvcu/Y40IzGT2A+aUhmV9EDCfrpe b0rHIg/ReSfDkDE0ZmOGMQ3gn6XQXGKCrL70HsrwBHRn8wl3rIr7p8cN6bX0XWCnulAQ RAYfJkqQs0N0eGs/mi2SnW2tlh8ew7/SA1rKCEdHfsK09zDCLWpIeMEMIlSM9tybvW0b uGuQIckQskovPVad4Ig0YBo+nxMhy+/aBwU+qA2KPbY5fHw+VfyK7WJ9BXNWlgvRFggJ x67r8Fiy0diMC88l4hOccN20y0tCyIf8Xsw2KsDr2TIxKSP0T3iy5bgiYKaxfRd6wwsm 8Ybg== X-Gm-Message-State: APjAAAWlR9dkpelzOzJ+eALu2l4Zc6E4pQi6w2yrGW7TcKH89VvxzMdh 7Kg/o3wFqWHtj+Rvg7i3/BtTwcXA X-Google-Smtp-Source: APXvYqyez3e1rptva5JOogzFskmNkMa5/F3i8AlkhtMfGv5Oq4iGDr1pMP6hITsV6T5BbHHvxhM71w== X-Received: by 2002:a5d:6ac3:: with SMTP id u3mr2034545wrw.206.1571994744266; Fri, 25 Oct 2019 02:12:24 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id d202sm1516724wmd.47.2019.10.25.02.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 02:12:23 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 25 Oct 2019 11:11:47 +0200 Message-Id: <20191025091147.5298-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191025091147.5298-1-andreas.rheinhardt@gmail.com> References: <20191025085222.4498-1-andreas.rheinhardt@gmail.com> <20191025091147.5298-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avformat/flvenc: Add deinit function X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes memleaks when the trailer is never written or when shift_data() fails when writing the trailer. Signed-off-by: Andreas Rheinhardt --- libavformat/flvenc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index a2bd791c59..228900f028 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -810,8 +810,6 @@ static int flv_write_trailer(AVFormatContext *s) put_amf_double(pb, flv_posinfo[i].keyframe_timestamp); } - av_freep(&flv->filepositions); - put_amf_string(pb, ""); avio_w8(pb, AMF_END_OF_OBJECT); @@ -1076,6 +1074,14 @@ static int flv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) return ret; } +static void flv_deinit(AVFormatContext *s) +{ + FLVContext *flv = s->priv_data; + + av_freep(&flv->filepositions); + flv->filepositions_count = flv->filepositions_allocated = 0; +} + static const AVOption options[] = { { "flvflags", "FLV muxer flags", offsetof(FLVContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" }, { "aac_seq_header_detect", "Put AAC sequence header based on stream data", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_AAC_SEQ_HEADER_DETECT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" }, @@ -1105,6 +1111,7 @@ AVOutputFormat ff_flv_muxer = { .write_header = flv_write_header, .write_packet = flv_write_packet, .write_trailer = flv_write_trailer, + .deinit = flv_deinit, .check_bitstream= flv_check_bitstream, .codec_tag = (const AVCodecTag* const []) { flv_video_codec_ids, flv_audio_codec_ids, 0