From patchwork Sun Aug 27 16:31:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 4857 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp1662004jao; Sun, 27 Aug 2017 09:32:16 -0700 (PDT) X-Received: by 10.28.12.208 with SMTP id 199mr2660783wmm.48.1503851536116; Sun, 27 Aug 2017 09:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503851536; cv=none; d=google.com; s=arc-20160816; b=YlWiRe8uPlbnRPjodCgoPPLkRIPaxyeuTOPYfpkhRJjSufOsOkVDlKRWahgqbYFxJL pgj89OiMs3D5n6NyEuMT+kLZx6JdWiwnNgh/wEAw5UddM2n8SMkJzVrDVK2IP7e4IImh BXqvVTYGnVYa5sarIlhBzBE39QrWPUYTykWBYxlwDXsD0OoF/OtAuiVFwwadeFCj/Okh jtqV4lDZPyrnsSwSdpuEdgIvRM8vqc/jOWayw8GuqXFoEeMVD47CNCLwtIkuTdJ4MJ25 fPMAjybLupduMDLXyIdC8yy2c768snUloKXWTqqhhUx8fCsZqrBxPBsiw6beGXoQ3h1g 0fEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=IWKYDwh2rorUxQhbMcrMYhI5lK4C6fJxqjup3BKBFsI=; b=kB+wGHyVzysxebhhLFSMQewP2VnY9+hJeeptVuOV2OWGCu2izSs5SkqbNwTvShXtvc gPkx9r4EjQ2KOYE42B5GzT5ao4ilD6jYYGtqzv1qIV1PACFhZfLvrD7kArq8Xeyi3HBB SY5pwYPrvghTWtehECPutCanH2E2kaFlch0ZcISV0mhc9z3dmLNHCmU4yFGX2aMB+GTP /MC88kzYuGz1M/DLJLE/l0/x9PC+u58igoeAE6nuC5pkf0ZNHU15PTDjNwm1Q2489ijN hLHBvPZfFfrNRQTSVX3p1IoKWfG1kGC1+0SovTzXBHqIDJPGMhOBnjp6yfFO7/SKjPaD Vn5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=a19QBLYg; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p46si925382wrc.553.2017.08.27.09.32.15; Sun, 27 Aug 2017 09:32:16 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=a19QBLYg; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C9E42689A80; Sun, 27 Aug 2017 19:32:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F7C16899B2 for ; Sun, 27 Aug 2017 19:31:57 +0300 (EEST) Received: by mail-qt0-f194.google.com with SMTP id g13so3491571qta.4 for ; Sun, 27 Aug 2017 09:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=Y+ZUF9EP31YtCil4fy/oqZh8p62Hs0VRxICIfYY+irE=; b=a19QBLYg95b/Km8veJZ1Hr5gBGAi6oII+H+RgnZyxHYZOI6NJWnWbyehim9+VIacm3 0D4sF1zKnrHEIhCPTDue8VdCce3mOY1eJVJCXsl7oe0eDLasvDe67Wh/YJGAz1K9W5ux bUHeP1Kfqv5Rg8wsJHP8QJ4PMl+gIy1uI5BjzUH6XoE2mvudkSYmpOoDpJTYcbmDDEfX eNQuLUhYprTLP/NlefwhQYMX7JEfeVruhf6/IumyQ0uGJ5BEcDpeBdHn7YSORLVHSD6t m5vGTqLpRDIg6YtKZVOiPCSopRNQM9ikeYBIAxr7Z9+7EL9SX2VycMKIjGreyZW855dN U4Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Y+ZUF9EP31YtCil4fy/oqZh8p62Hs0VRxICIfYY+irE=; b=CRMoKHDQ6wPHnLp83uEUYNAWydF29nZlQfblxGZwSXcgU/D0emss05MFFnq70JvK3A LSSYQpiW1QCWW53g/A1HpVR17OsDgRs4Qt6aZyOjQEPHPym8ZCr5Shq7D4dIdMlVd9mg ubSrfOkEYwb8GE66NPl7104Hs0DiF9+q9IhaV9AUDIUF5o8JEdyOcC0NWV9MwmvP4n1O khuAs9m6CMEdO10ZEN5sZgt9oNWw8DhPrOgCAgFy3u9NWvorGBEqEAJmnW0q//bEfonR pm/kkjRw0HCT/LotTuC6Bpj3VXlnA463iUzSKRu+mqtjIZ0V0HUYSzcKp+mo98cVhjmn MMKA== X-Gm-Message-State: AHYfb5juVKCfQ3xh5w5+Bewdt2+xE5EzDXRZGoPUo3IFJ/umLwm0mrp3 1tOdBYLIf1MX7S8N X-Received: by 10.237.37.235 with SMTP id y40mr6196156qtc.178.1503851525324; Sun, 27 Aug 2017 09:32:05 -0700 (PDT) Received: from localhost.localdomain ([181.231.116.134]) by smtp.gmail.com with ESMTPSA id s124sm4202898qkc.5.2017.08.27.09.32.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 27 Aug 2017 09:32:04 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 27 Aug 2017 13:31:17 -0300 Message-Id: <20170827163117.7784-1-jamrial@gmail.com> X-Mailer: git-send-email 2.13.3 Subject: [FFmpeg-devel] [PATCH] avio: add a destructor for AVIOContext 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Anton Khirnov Before this commit, AVIOContext is to be freed with a plain av_free(), which prevents us from adding any deeper structure to it. (cherry picked from commit 99684f3ae752fc8bfb44a2dd1482f8d7a3d8536d) Signed-off-by: James Almer --- doc/APIchanges | 3 +++ libavformat/avio.h | 8 ++++++++ libavformat/aviobuf.c | 17 ++++++++++++++--- libavformat/version.h | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 7babf5babb..880c791f5c 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2015-08-28 API changes, most recent first: +2017-xx-xx - xxxxxxx - lavf 57.79.100 / 57.11.0 - avio.h + Add avio_context_free(). From now on it must be used for freeing AVIOContext. + 2017-08-08 - xxxxxxx - lavu 55.74.100 - pixdesc.h Add AV_PIX_FMT_FLAG_FLOAT pixel format flag. diff --git a/libavformat/avio.h b/libavformat/avio.h index f14b003ba5..ea56dad503 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -467,6 +467,14 @@ AVIOContext *avio_alloc_context( int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t (*seek)(void *opaque, int64_t offset, int whence)); +/** + * Free the supplied IO context and everything associated with it. + * + * @param s Double pointer to the IO context. This function will write NULL + * into s. + */ +void avio_context_free(AVIOContext **s); + void avio_w8(AVIOContext *s, int b); void avio_write(AVIOContext *s, const unsigned char *buf, int size); void avio_wl64(AVIOContext *s, uint64_t val); diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index ec21fc7d38..716c42eda9 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -143,6 +143,11 @@ AVIOContext *avio_alloc_context( return s; } +void avio_context_free(AVIOContext **ps) +{ + av_freep(ps); +} + static void writeout(AVIOContext *s, const uint8_t *data, int len) { if (!s->error) { @@ -1123,7 +1128,9 @@ int avio_close(AVIOContext *s) else av_log(s, AV_LOG_DEBUG, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count); av_opt_free(s); - av_free(s); + + avio_context_free(&s); + return ffurl_close(h); } @@ -1356,7 +1363,9 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) *pbuffer = d->buffer; size = d->size; av_free(d); - av_free(s); + + avio_context_free(&s); + return size - padding; } @@ -1399,6 +1408,8 @@ int ffio_close_null_buf(AVIOContext *s) size = d->size; av_free(d); - av_free(s); + + avio_context_free(&s); + return size; } diff --git a/libavformat/version.h b/libavformat/version.h index 94081aca81..3029a5e767 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 57 -#define LIBAVFORMAT_VERSION_MINOR 78 +#define LIBAVFORMAT_VERSION_MINOR 79 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \