From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3EA2F42597 for ; Sun, 20 Mar 2022 22:12:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B7BAC68B0FD; Mon, 21 Mar 2022 00:12:50 +0200 (EET) Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D41AD68A906 for ; Mon, 21 Mar 2022 00:12:44 +0200 (EET) Received: by mail-oo1-f41.google.com with SMTP id y27-20020a4a9c1b000000b0032129651bb0so17155669ooj.2 for ; Sun, 20 Mar 2022 15:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=rZe98SNxPPLkPaXc14+TsBzBv9IocpgXz4tJms4Cmf4=; b=mUCWjRn2SKOP/3PGSZ/Yet5G9zz/pPYKNQHdBl6ZWkloJC5Aiwj9nVqPGZ2LGWHR11 9cC3fruViZH1S7sKCrgtqPcblagKfW4dqYc0dAw8XLVTKZ8XaYp/KWzDlo88xm0+hNsd CyRHv50IIHky0RjBaBr2xUbnw/PJNSICU12vCgIF75Swb0sZyYw76RbuxNCVYrmrOvcC EAEUdqLlXfsFDMSgqweRVx6eYuINdC4hmROFNHDUHxztRhw+nxyhFeUUEtTndkLr9an1 xN0VjOg6LZz4+DhE6vG+3/gRvIWBeigqrKtopqFa8NRq9E/nvMO97LVxttEfCMDSv7r/ U06g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=rZe98SNxPPLkPaXc14+TsBzBv9IocpgXz4tJms4Cmf4=; b=IM4an69BB0RgP4ZYmRh0L5pXP+NFmXKPZLxQ9hQHqGxpdKtLGRaCy9rJuvi+X05xGE KQpFxGlzP8d8lucO6bivL4MW3Xm5dlTjJVTRXTdcZjMJypbKlzVmbNvv/dCrvfC0v8ue Bo4ZK1nDmGE1jDSo9MiMSj8RaZSDpqQ2L35/491SYvRXbZ9KBfhOizgd8dXwaNO0G+48 mhA/xxe1ZsAFPfZJJQuPqfhVNJfx57h4ZQI8hcYAPVtWiWll83ru3qxtlKZ77PH45I99 WFcNQvEu9DCgNl+kOJq9Pf/TAbORtMtZ+vvimzFflLEJPgPzj0pK5/7MmJZRCGZsoEy8 795g== X-Gm-Message-State: AOAM531MpL6IQZ/IwCB7jBALW/URmZw22ANU6a8sdbbE+IG3Vs2OiGLA ATccsM2vd59aaF/WwTRb8OWncGSJneuVRQ== X-Google-Smtp-Source: ABdhPJxfH2KX826DTcZGjhfuQFJK5Dp9tOjM0J70Js0Wd+1d6tt7GHx/1ZHqAJ7KDzxZM1Z0Bg4u1g== X-Received: by 2002:a05:6870:311e:b0:d6:c423:d951 with SMTP id v30-20020a056870311e00b000d6c423d951mr10853873oaa.132.1647814362786; Sun, 20 Mar 2022 15:12:42 -0700 (PDT) Received: from [192.168.0.13] ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id 1-20020a056870104100b000dd9a2eb20asm5580179oaj.21.2022.03.20.15.12.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 20 Mar 2022 15:12:42 -0700 (PDT) Message-ID: <6995d99f-73e4-0a00-ee74-5feb194b093f@gmail.com> Date: Sun, 20 Mar 2022 19:12:43 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20220319030407.45503-1-jamrial@gmail.com> <7f619d76-a701-092f-863d-664eac5cd5ba@gmail.com> From: James Almer In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH] avcodec/avcodec: don't uninitialize ch_layout in avcodec_close() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 3/20/2022 7:01 PM, Hendrik Leppkes wrote: > On Sun, Mar 20, 2022 at 7:52 PM James Almer wrote: >> >> On 3/19/2022 4:50 AM, Hendrik Leppkes wrote: >>> On Sat, Mar 19, 2022 at 4:04 AM James Almer wrote: >>>> >>>> The function is not meant to clear codec parameters, and the lavf demux code >>>> relies on this behavior. >>>> Regression since 327efa66331ebdc0087c6b656059a8df2f404019. >>>> >>>> Signed-off-by: James Almer >>>> --- >>>> libavcodec/avcodec.c | 6 ++++++ >>>> 1 file changed, 6 insertions(+) >>>> >>>> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c >>>> index 38bdaad4fa..253c9f56cc 100644 >>>> --- a/libavcodec/avcodec.c >>>> +++ b/libavcodec/avcodec.c >>>> @@ -469,6 +469,7 @@ void avsubtitle_free(AVSubtitle *sub) >>>> >>>> av_cold int avcodec_close(AVCodecContext *avctx) >>>> { >>>> + AVChannelLayout ch_layout; >>>> int i; >>>> >>>> if (!avctx) >>>> @@ -524,7 +525,12 @@ av_cold int avcodec_close(AVCodecContext *avctx) >>>> >>>> if (avctx->priv_data && avctx->codec && avctx->codec->priv_class) >>>> av_opt_free(avctx->priv_data); >>>> + /* av_opt_free() will uninitialize avctx->ch_layout, but we want to keep it. >>>> + It will be uninitialized in avcodec_free_context() */ >>>> + ch_layout = avctx->ch_layout; >>>> + memset(&avctx->ch_layout, 0, sizeof(avctx->ch_layout)); >>>> av_opt_free(avctx); >>>> + avctx->ch_layout = ch_layout; >>>> av_freep(&avctx->priv_data); >>>> if (av_codec_is_encoder(avctx->codec)) { >>>> av_freep(&avctx->extradata); >>> >>> This feels pretty ugly and still a bit risky that any call to >>> av_opt_free could invalidate data its not supposed to. Maybe we should >>> have a flag for AVOptions instead where av_opt_free won't touch an >>> entry, because its only there to set/get it, not manage its memory? >> >> Where would that flag be set? av_opt_free() takes none. And that >> function exists purely to free strings, dictionaries, and now >> uninitialize AVChannelLayout elements in a struct. If you don't want to >> free what av_opt_set() allocated, you shouldn't call av_opt_free() at all. >> > > On the AVOption element in the table, with the other AV_OPT_FLAG_* Oh, you meant flagging the actual AVOption. My bad, i for some reason thought you meant having the user flag which options they wanted to "own". I'll try to implement this. Any suggestion for the flag name? AV_OPT_FLAG_NO_FREE? > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".