From patchwork Sun Jun 14 22:36:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20353 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 6F3C244AF2E for ; Mon, 15 Jun 2020 01:37:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4B4AB68B2E0; Mon, 15 Jun 2020 01:37:15 +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 B91E468B029 for ; Mon, 15 Jun 2020 01:37:08 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id r7so15195112wro.1 for ; Sun, 14 Jun 2020 15:37: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=VjCkHN+zdEjl3H8iTEQ0z42yePuHOTeHV743bLkW7aw=; b=cTlT3TRO+R2q/liPsLVhrUPts+CWNr9ShnC9K/LvWVlePJHgU1k6GjjQgCfe6Hw24z eP5G7Yez9Vn/ioWW1cfPIVtKJzRuoM/gks8gjt75pJqtFDpUjxfkJ0gPZ+vdBPwrTklE gwBsuFmy5gWBpPnSVzIjacYueeCp2nivlWvCHbvelG79/kzFFT+RCk1y7LhhuUQoXITO jPlZG14j5uMvpp4YlXhwE7vHQOLdQBqplagbSeO2/I88gXLLRK37JKQd4IpxirQ4ZtHG kjJP7YKDQX6gN/iD4/hnf3RYOq/Nm4UcYH09oKnF5kwNLaTSJS1AZ4hf3LeqtkHMM935 zneA== 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=VjCkHN+zdEjl3H8iTEQ0z42yePuHOTeHV743bLkW7aw=; b=m3zXlFBJsb+jKod/nkd0amgzsJCQdfFWcJPaPiFJNtY4yEktIWy1h8VdQbeM8I5DSu N5mHuB19yFAbcyV/8Jf2iimvB//+aHebC6ULHOwSZyFqmIx3Mm4YAuBRGRzsqAUy517D TNaerDZLzPUsiX1lFh8+h/uLHhzcLCgCZrnmKtt6Z66nSBaF99ULJuhBDpXToA051zTw F7GoCK55ek7V+PcxR8Kaii63/3Ay2qF07uuUJS8sT7Qpdmg8yd2o4RhdFLwZU1MNP5PS XACPx6c79t5QRxmKSwi8t9pwF/CIWSfdecFsTrEY+RTABCsc1lguKltm5VspfCswRgB2 Lg1Q== X-Gm-Message-State: AOAM533XM70AhA0MicNQIrbLckwjbOsN0PxxF1ee5Yz39VbMk+DmNXVS O3DRHH0uijcD2hIUKgehcSbfiiDJ X-Google-Smtp-Source: ABdhPJz6tQtR7D4Q2gkepV1MShyQ00id0vv33hIN6e0ZmMH4oqOdFnH/fFHOK1q48Tp7dImxRMX21w== X-Received: by 2002:adf:a283:: with SMTP id s3mr24397134wra.147.1592174227951; Sun, 14 Jun 2020 15:37:07 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id z8sm21491034wru.33.2020.06.14.15.37.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 15:37:07 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Jun 2020 00:36:31 +0200 Message-Id: <20200614223656.21338-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/26] avformat/matroskadec: Move AVBufferRef instead of copying, fix memleak 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" EBML binary elements are already made reference-counted when read; so when populating the AVStream.attached_pic, one does not need to allocate a new buffer for the data; instead the current code just creates a new reference to the underlying AVBuffer. But this can be improved even further: Just move the already existing reference. This also fixes a memleak that happens upon error because matroska_read_close has not been called in this scenario. Signed-off-by: Andreas Rheinhardt --- This fixes one of the memleaks that I found during the work on my patchset [1] that intended to automatically call a demuxer's read_close function if reading the header fails. Several other of the patches of this patchset also fix such memleaks. I intend to apply this patchset soon so that 4.3 can finally be released. [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-March/258831.html libavformat/matroskadec.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index bb3a126c29..b1da40983f 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2938,9 +2938,8 @@ static int matroska_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; av_init_packet(pkt); - pkt->buf = av_buffer_ref(attachments[j].bin.buf); - if (!pkt->buf) - return AVERROR(ENOMEM); + pkt->buf = attachments[j].bin.buf; + attachments[j].bin.buf = NULL; pkt->data = attachments[j].bin.data; pkt->size = attachments[j].bin.size; pkt->stream_index = st->index;