From patchwork Fri Sep 20 20:39:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15193 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 33B814498BB for ; Fri, 20 Sep 2019 23:40:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F3F968A60E; Fri, 20 Sep 2019 23:40:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AD8AB68A59A for ; Fri, 20 Sep 2019 23:39:56 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id f16so3451279wmb.2 for ; Fri, 20 Sep 2019 13:39:56 -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=6LZWdtVOu4hz/uAHYReRvdrgq54wMWHGpDCdqn0w7YY=; b=VWduXHyOlONOTmLxBC1NGhh1j/73MuwwJBlV4S9L+LuFlShFJCJapo4tSdvsPDPi6Z hAqMVb1nWv6DezEOFDZq4tE554oigVLjR7UmojO7adWfA880q971vKBrtDx+kh0vBMEl Pmsh9eCgalQMnfHWEkNx7MKhvD9gaGQOfb0lVyuy1wIKIFx2iCMHHkdP6Tjke9WQc79E oXS/aDE25OkhS2/vx2knHnuUI7riQItxJWbNHRbSF7L6vLTgCer9cEVckAOJNnGH0SSt 5Dm3r8wIJdvyLuiC38osd2PTeLMEgNV58YkSh7Negre5iZI3RZwL8dmJeYVvB3sYnaYY BHvg== 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=6LZWdtVOu4hz/uAHYReRvdrgq54wMWHGpDCdqn0w7YY=; b=i5g3cdcvbigTMlxItZH5hvoc+nCvqhcakb2gkchQ1GSycCKjpxdaeYiLKqOTxbo0Dd xEuhEAizxtWEVjjtX4FRGhZ3zb5YEWizwR0bPK4PiIxujY4CIIYjSST2Jvqi+qFrTW3J uHorfT5Z6lXS59wiPMDso14DrDTB+iolN9+GKNdcA4mxaWJM7PpCb5tH6uHcCxuXJCiu /1cGdUuM2/ad6YNf7U6wprkoX4STfkWy7qYSjsK+b7atupbyuqG2gkKzIKt1NrfOMqnZ CpGhA/kvx1hp0AEMFYu7W3dhfgrDufTX6qWQG9/ZGWbrY78NFz9tSQhmuFuVgn2QSreu umrg== X-Gm-Message-State: APjAAAVqCDjOfwj+2IYdui4WrQrvJA+bZ8bK07qfyoboeYjBrioyH0ht +NA7/AZ0Mo9sX0F0MbqZoFUZTyt5 X-Google-Smtp-Source: APXvYqwAMf5GUC1kZm5A4kHHsot6lu0M0g2fL+EFzvsyPKbOseAlJAOkWKevIhjYzo5fYuCgkXcICw== X-Received: by 2002:a05:600c:2208:: with SMTP id z8mr5169784wml.113.1569011996012; Fri, 20 Sep 2019 13:39:56 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc0f857.dynamic.kabel-deutschland.de. [188.192.248.87]) by smtp.gmail.com with ESMTPSA id m62sm3734041wmm.35.2019.09.20.13.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 13:39:55 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Sep 2019 22:39:12 +0200 Message-Id: <20190920203916.16904-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190920203916.16904-1-andreas.rheinhardt@gmail.com> References: <20190920203916.16904-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 5/9] 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 was 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 cf326ad014..701e9ea030 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3810,7 +3810,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 { @@ -3825,7 +3825,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; } @@ -3913,7 +3913,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 @@ -4189,6 +4189,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)