From patchwork Fri Aug 16 16:43: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: 14552 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 54C1A44A297 for ; Fri, 16 Aug 2019 19:44:14 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1CD5468AB99; Fri, 16 Aug 2019 19:44:14 +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 1A02268AB87 for ; Fri, 16 Aug 2019 19:44:08 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id t16so2134522wra.6 for ; Fri, 16 Aug 2019 09:44:08 -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:mime-version :content-transfer-encoding; bh=14WZXoXDkRAn0z1R4Z8NbxT0EjNIUo3ISNoMHOByirY=; b=YjID4B4wTL5vIhPOA3h3M2NPNQmN4+KUXDCBXPz2FhyGT6N+faUCXIbiIjuCIqPMAV jqrE/4XE6eAVv//xMPQrGwoW1Hr46UYzMVEoOcR72lZlGyKUklEYTFwvrxxrYw3AD05y e9nFFeEB7P5Ul98Pl4BVlSd5tH9xXxKEB3Kl/TZAz5FW4kFycLY/mCUAcYB14lR2EJkN YLRIjoKhLTfOmPMKXg0zvgIYGRKfsb6rEQdOGBHrAZNlxLhJPt6CbOGNCpGVI54RImzr ei9bqKkZ2oG8ueWfwexqy5FPLwBBAzmAzLybh40nmo4bw0RnvIP+3VncvWYomL0t/KZz nlDQ== 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:mime-version :content-transfer-encoding; bh=14WZXoXDkRAn0z1R4Z8NbxT0EjNIUo3ISNoMHOByirY=; b=oWkkxc4BmdoaN7l5OmnFH+zol+WBAKilC3NeFnoux9WBBN2y8mAfILNm0b4ld5Gve6 DIw37ntJ+KBJXrzuaLxX3cQkGESSXGqaQM0YW0nPwiE0OWLIRgd8QHHYjS35rRCmS9fJ P4e9AE7YSq0wWb7qf1cP2VwOLC/uRHtM7ZpYLe9+sf+VoK7/xFvvciPNpHGl1fc1C27q YthASRy7+XVCCnhlFrL82CJGL2alw5MBTPvS3B2NvnrPYipPTKKs4j8KdW/pk9ieEVBQ bmS5HI9GCGY0C9eYhMMYHk/NEIaKDn8XYgIcmp103OldelsiUZjSUhH9ECj8v/qlwvYv 4BBw== X-Gm-Message-State: APjAAAUOB+R/CiiVw5ggWKVYyftcvn7hl1h4px+GEFdPViDZylkoSYAc uek7RLF5Gdi1dYyS3t+UECnI48XD X-Google-Smtp-Source: APXvYqzACD3HNWmxt3IBexLRcTwjIUqL9rMbHl49VzDPOznwg4zV5X61dmOoJBHmsf8MWXVuKRxO3Q== X-Received: by 2002:adf:dcc2:: with SMTP id x2mr12700581wrm.295.1565973847389; Fri, 16 Aug 2019 09:44:07 -0700 (PDT) Received: from localhost.localdomain (ipbcc08b69.dynamic.kabel-deutschland.de. [188.192.139.105]) by smtp.gmail.com with ESMTPSA id n12sm3845461wmc.24.2019.08.16.09.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2019 09:44:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Aug 2019 18:43:12 +0200 Message-Id: <20190816164314.57764-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/utils: Fix memleaks 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" ff_read_packet had several potential memleaks: 1. If av_packet_make_refcounted fails, it means that the packet is not refcounted, but it could nevertheless carry side data and therefore needs to be unreferenced. 2. If a packet happens to have an illegal stream index (i.e. one that does not correspond to a stream), it should nevertheless be unreferenced. 3. If putting a packet on a packet list fails, it wasn't unreferenced. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index b57e680089..a902841ad5 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -873,8 +873,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) } err = av_packet_make_refcounted(pkt); - if (err < 0) + if (err < 0) { + av_packet_unref(pkt); return err; + } if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) && (pkt->flags & AV_PKT_FLAG_CORRUPT)) { @@ -887,6 +889,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if (pkt->stream_index >= (unsigned)s->nb_streams) { av_log(s, AV_LOG_ERROR, "Invalid stream index %d\n", pkt->stream_index); + av_packet_unref(pkt); continue; } @@ -917,8 +920,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) err = ff_packet_list_put(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end, pkt, 0); - if (err) + if (err < 0) { + av_packet_unref(pkt); return err; + } s->internal->raw_packet_buffer_remaining_size -= pkt->size; if ((err = probe_codec(s, st, pkt)) < 0)