From patchwork Wed Oct 23 12:59:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15917 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 1169044A928 for ; Wed, 23 Oct 2019 16:07:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EDD4268AED3; Wed, 23 Oct 2019 16:07:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B2B4568ACC0 for ; Wed, 23 Oct 2019 16:07:09 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id o28so22012788wro.7 for ; Wed, 23 Oct 2019 06:07:09 -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=cqJntgDmQBdloOHCW6UkNsvCy9Hp5xSAr9L9bjQEl4Q=; b=SbxZW13TfbEknaENUUdpamhSNXKScSMbD62xByyRC5f4u6n4Pc8niebISFvOcuMDMk gP67pP6Exge+uFJiplZin9DMB9WDcXD0TLFBuIAJhrF5YK8+9q7oBCxRxnhMIvgclXWX 8i+Gkfzs6J3+65umFFsGekLsKmClVM322XObS1plnhX+yzWJjpUwLqb07HIPIOuAN4sz nWHRkAfYtwT3izVHGrYa26F3OuOSs4G9QolhiI9FSyERdTLk0g3iA4kRS9LXkKBp+Nno dXcCG5XDm5O7aQ9MkpbWNqVZNtftgWl9IcOuF9T58ZFS4xpYufIEc43O9e8x/dUG1eG4 GuNQ== 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=cqJntgDmQBdloOHCW6UkNsvCy9Hp5xSAr9L9bjQEl4Q=; b=iHV766Ux1/eV6cYKyD0pWqteuE0/wI6sRVm7jRgzrZCOQWorVbMZtRObKROoWJjA7C R5J481XB7EJnOUprO0lZK0F67fzpOL4+m7gSCvTy/mB0/ixc0c3w3ij6MxTnxZtqEehl qfLgRg5atlFGSwiaPZZoLgOgUcs8TxGixkYUWUDC6BK++yRVoagFqjwbo5Ylu476G08K gAYYGtvMuXBHD6uzorDhu8PWjO3mArREmcDFJVpt/VpoELYgLvZynHGiUbnLOVbzK1kr y7jM++aCSeDVbjzuYRae9PsbGjcGTw7zMhPnMsXXZDlZ+/qkYNRXv7//xING6l697zDq 4XZg== X-Gm-Message-State: APjAAAUAIANxTLpDgqpfhkU1MB7C7zSK7Y3l+Uv7MtlUXpGzUgMJnyfK DQT7pazgclRei0f7OhmeeOO/BTWy X-Google-Smtp-Source: APXvYqy94MdV+fY82Q4pBrJOh8ax/7bxoig9GND8X5YQbpkNT9xt7jo9eb9CijHGApiLl3C+O/xzAw== X-Received: by 2002:a5d:4902:: with SMTP id x2mr8808670wrq.374.1571836029085; Wed, 23 Oct 2019 06:07:09 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id c144sm5303125wmd.1.2019.10.23.06.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 06:07:08 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Oct 2019 14:59:42 +0200 Message-Id: <20191023125944.10292-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191023125944.10292-1-andreas.rheinhardt@gmail.com> References: <20191023125944.10292-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/6] 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 | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index fb1dede7ae..0da54f3365 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -784,7 +784,7 @@ static int flv_write_trailer(AVFormatContext *s) int64_t cur_pos = avio_tell(s->pb); if (build_keyframes_idx) { - FLVFileposition *newflv_posinfo, *p; + FLVFileposition *newflv_posinfo; avio_seek(pb, flv->videosize_offset, SEEK_SET); put_amf_double(pb, flv->videosize); @@ -819,19 +819,6 @@ static int flv_write_trailer(AVFormatContext *s) put_amf_double(pb, newflv_posinfo->keyframe_timestamp); } - newflv_posinfo = flv->head_filepositions; - while (newflv_posinfo) { - p = newflv_posinfo->next; - if (p) { - newflv_posinfo->next = p->next; - av_free(p); - p = NULL; - } else { - av_free(newflv_posinfo); - newflv_posinfo = NULL; - } - } - put_amf_string(pb, ""); avio_w8(pb, AMF_END_OF_OBJECT); @@ -1093,6 +1080,20 @@ static int flv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) return ret; } +static void flv_deinit(AVFormatContext *s) +{ + FLVContext *flv = s->priv_data; + FLVFileposition *filepos = flv->head_filepositions; + + while (filepos) { + FLVFileposition *next = filepos->next; + av_free(filepos); + filepos = next; + } + flv->filepositions = flv->head_filepositions = NULL; + flv->filepositions_count = 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" }, @@ -1122,6 +1123,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