From patchwork Thu Jul 11 04:29:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13893 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 111AC449623 for ; Thu, 11 Jul 2019 07:29:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D958168AB0D; Thu, 11 Jul 2019 07:29:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0DAC268A9B4 for ; Thu, 11 Jul 2019 07:29:40 +0300 (EEST) Received: by mail-pf1-f193.google.com with SMTP id i189so2106796pfg.10 for ; Wed, 10 Jul 2019 21:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=u431xEAqBuUQpmyzV5u3g++A2rsqAOEVdTDDotDmht8=; b=DkoYhSzaN6Ta4yrs2/zKx00qNaiKY8jFfTsR/E2Qn4cREeLylDi4e/X55PBA6uAbVZ EYSqvJYvV+lvN4XUFqzB26r1Zry2A3vRY4qjNu2FW8asZxNaDsBJXl4BGg6C4HPSoOuD XNWwcrsQXV7TMjW+n1vCl+/V3hYmoI82IGXtzT6PzIrT2h3s4fhS+N+KeVWCw3tvZArS MQfcoHndmotBJocukQJF5zR7DZ6vP5t/kSsJKRAFst6uImXZVqY2Rg3B2/oJbVDG4+eK VPiQybuD5/1GUK1POHzR2xkkpz7YN3o0pkoU+8mtIsPaGaY2rNANKXE1vGIn/LGFKHuE i11g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=u431xEAqBuUQpmyzV5u3g++A2rsqAOEVdTDDotDmht8=; b=lArCr8TBCgwJZz2GsQ+Sywq0lVvyr6gaEHYaDWLc/RMChcW71aZi4AS4oOX2Ftdj5k TFlvAP784URCdj2B6C/0V+IFDWRN+MQcdpNe8nQBUoB9NKKESyUpZDGfZW2efCdsyaEv TKDkMOI5If7gLYWFW1TJx5uKNXJwNs4eOu1gVRmCyR2L62IIDWOvlwwdhJlJtbXrqjvk mBnG3p0rS9nxuAGdL9tNJsDp9WvI3c/WzSFB8PA1prPMiniq+X5ZtF5IvlFoWEJ/+15E 1tPEcgHlQ6iXr7IMCtuHn+a1/znIe8+7LukzfMiXppxfmH0eEouZ6rgVBEE5+7six1kx pWoQ== X-Gm-Message-State: APjAAAWZJSmQTo6Ng28fdEL9M1UPiXJ8FGHWvvtO92zEABdok1VSoE72 sVa8wEaudkRlgbr7IZmlbB6293wh X-Google-Smtp-Source: APXvYqymET5hnCkkIS7/o7JZlAKVRpZN83ssDL4W2I9NDpPn/4wMm5j9xq+3L1LsGLO1yiRTP2VKzQ== X-Received: by 2002:a63:ed06:: with SMTP id d6mr2120993pgi.267.1562819377551; Wed, 10 Jul 2019 21:29:37 -0700 (PDT) Received: from izj6c97garwn1o4y2zidq0z.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id 34sm3948881pgl.15.2019.07.10.21.29.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jul 2019 21:29:36 -0700 (PDT) Date: Thu, 11 Jul 2019 12:29:33 +0800 From: Limin Wang To: FFmpeg development discussions and patches Message-ID: <20190711042933.GA32155@izj6c97garwn1o4y2zidq0z.localdomain> References: <20190618104513.19549-1-lance.lmwang@gmail.com> <20190618104513.19549-2-lance.lmwang@gmail.com> <20190710144833.GA31052@izj6c97garwn1o4y2zidq0z.localdomain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [FFmpeg-devel] [PATCH v1 2/2] libavformat/file: initilize the fd to -1 instead of 0(valid fd) in case unexpected file close 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Thu, Jul 11, 2019 at 11:16:49AM +0800, mypopy@gmail.com wrote: > On Wed, Jul 10, 2019 at 11:11 PM Limin Wang wrote: > > > > > > ping? I have developed code to use avio_open_dir function, after using avio_close_dir > > to release the resource, my ffmepg command will lost interact for the fd > > 0 is closed by avio_close_dir. > > > > > > On Tue, Jun 18, 2019 at 06:45:13PM +0800, lance.lmwang@gmail.com wrote: > > > From: Limin Wang > > > > > > Signed-off-by: Limin Wang > > > --- > > > libavformat/file.c | 1 + > > > 1 file changed, 1 insertion(+) > > > > > > diff --git a/libavformat/file.c b/libavformat/file.c > > > index 08c7f8e6dd.. 40ae9ad2a8 100644 > > > --- a/libavformat/file.c > > > +++ b/libavformat/file.c > > > @@ -274,6 +274,7 @@ static int file_open_dir(URLContext *h) > > > #if HAVE_LSTAT > > > FileContext *c = h->priv_data; > > > > > > + c->fd = -1; > I don't konw why need to change the fd , suppose we have a calling > sequence like file_open ahead of file_open_dir, can we leak a fd > resource ? How to reproduce the issue: 1. add one debug message like below: 2. build the examples with make examples 3. run below example tool: ./doc/examples/avio_dir_cmd list ./doc/examples 78056 transcoding.o 501(20) 644 1562818479000000 1562818949000000 1562818479000000 18744308 muxing 501(20) 755 1562818948000000 1562818948000000 1562818948000000 [file @ 0x7f8e50406700] fd: 0 You can see valid fd 0 is closed unexpected, if you run in ffmpeg with avio_dir_close option, you'll lose interaction cli control for the close. > > > c->dir = opendir(h->filename); > > > if (!c->dir) > > > return AVERROR(errno); > > > -- > > > 2.21.0 > _______________________________________________ > 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". diff --git a/libavformat/file.c b/libavformat/file.c index 08c7f8e6dd..f06f1aa506 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -266,6 +266,8 @@ static int64_t file_seek(URLContext *h, int64_t pos, int whence) static int file_close(URLContext *h) { FileContext *c = h->priv_data; + + av_log(h, AV_LOG_INFO, "fd: %d\n", c->fd); return close(c->fd); }