From patchwork Mon Aug 19 21:56:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 14597 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 A1890446D22 for ; Tue, 20 Aug 2019 01:11:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B6B668AABC; Tue, 20 Aug 2019 01:11:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 865FA68A0FA for ; Tue, 20 Aug 2019 01:11:10 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id t16so10257438wra.6 for ; Mon, 19 Aug 2019 15:11:10 -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=Ya3D400RG1meACZFFzRwCyiQ8pwUowUsg2fzn+PF0SI=; b=nGUDDO4rzN4SbpJyMrsB74gvwG9TD/qQ1dxS+UiJG/RxZ/SKDnWhoKrLIkeoOsSw76 1s0J25tU1xF0bQC26j7qBFmdGd1wYPjkFURfASX7vg4rGbJgkFuxF9zZGObo1pD8QFV1 UqQZ08ndUjz1h87ubp43AePvXyrOFFCsUvcW78gEH2w+aZg6713Dr5mOxh2OQgcgU6vx TjqNd7CciSmr78XmdcVR8E7JGdJEXp+m9mDbUkem7krWIsS/QB4KIOPjJJbRB8WjynPa fY19XB9+b6zdXTG47HlqpMnFtSDdpBIBkffTOUnyuvUBTJw4LseZe87k4CbGbIpwbmAf FG6A== 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=Ya3D400RG1meACZFFzRwCyiQ8pwUowUsg2fzn+PF0SI=; b=fj6suzXC8hX0GRktcssvVQemMWVRgsWtk3kQDGW60UU8/SpyeBAA9CICEsOOycI9sz 1Pfh5SsIvtFf+adEbpQVVp75NPdtYOTTpS/NwmKPJoRHOJzhXBIOsQ8kf+NQjHorlx9O +05C0s4DjoVelqt86DP7sLpNZjmKaQfZY1sj3+KphuTQXRojQEqEwvZhLK2fFNY4KgyI hv1S4r2J3NiObVEjkyQiaLoujMf1TTF8A/LIAi7oTLFYMvPzcketbxnn2x+x/lD6yRqu oG844itLsrHz8PbNEM7wdzR1YbjFo9IFuOBtc6qpOmMN2mZHr64cL1X4hCJZmeNNJOsG cq1g== X-Gm-Message-State: APjAAAVgi3nYaje4x0McdsPiIvJX+5VjI+RrXG/P1/EE4D5GhmPzoB7d PGVG7owvLhx38W/Tc/8uibV0Kkr7 X-Google-Smtp-Source: APXvYqyRMHRVUKjedQREpc4UKr3oz3fGOyIxYoROJNUpuiSfqZ9X8imQhyWTwU6+vETe6qPP22mv0w== X-Received: by 2002:a5d:4ecf:: with SMTP id s15mr12959068wrv.49.1566252236086; Mon, 19 Aug 2019 15:03:56 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c5c.dynamic.kabel-deutschland.de. [188.192.140.92]) by smtp.gmail.com with ESMTPSA id s64sm32952293wmf.16.2019.08.19.15.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 15:03:55 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Aug 2019 23:56:21 +0200 Message-Id: <20190819215624.49795-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190819215624.49795-1-andreas.rheinhardt@gmail.com> References: <20190819215624.49795-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 5/8] avformat/utils: Fix memleaks II 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" Up until now, avformat_find_stream_info had a potential for memleaks: When everything is fine, it read packets and (depending upon whether AVFMT_FLAG_NOBUFFER was set) put them in a packet list or unreferenced them when they were no longer needed. But upon failure, said packets would leak if they were not already on the packet list. This patch fixes this. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index bae2f9e0db..96c02bb7fc 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3801,7 +3801,7 @@ FF_ENABLE_DEPRECATION_WARNINGS &ic->internal->packet_buffer_end, &pkt1, 0); if (ret < 0) - goto find_stream_info_err; + goto unref_then_goto_end; pkt = &ic->internal->packet_buffer_end->pkt; } else { @@ -3816,7 +3816,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!st->internal->avctx_inited) { ret = avcodec_parameters_to_context(avctx, st->codecpar); if (ret < 0) - goto find_stream_info_err; + goto unref_then_goto_end; st->internal->avctx_inited = 1; } @@ -3904,7 +3904,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!st->internal->avctx->extradata) { ret = extract_extradata(st, pkt); if (ret < 0) - goto find_stream_info_err; + goto unref_then_goto_end; } /* If still no information, we try to open the codec and to @@ -4180,6 +4180,10 @@ find_stream_info_err: av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n", avio_tell(ic->pb), ic->pb->bytes_read, ic->pb->seek_count, count); return ret; + +unref_then_goto_end: + av_packet_unref(&pkt1); + goto find_stream_info_err; } AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)