Re: [PATCH] tools/gpio: prevent resource leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 09, 2023 at 03:53:45PM +0200, Andy Shevchenko wrote:
> On Thu, Nov 9, 2023 at 2:36 PM Kent Gibson <warthog618@xxxxxxxxx> wrote:
> >
> > On Thu, Nov 09, 2023 at 04:54:19PM +0800, heminhong wrote:
> > > In the main() function, the open() function is used to open the file.
> > > When the file is successfully opened, fd is used to interact with the file,
> > > but the fd is not closed, it will cause resource leak.
> > >
> >
> > All open files are automatically closed when a process exits.
> > That includes both those returned by open() and by the GPIO ioctls.
> > So explicitly closing them here before exiting is redundant.
>
> I would argue that this is a good practice for GPIO cases.
> More the GPIOs we have, the more line handles we can get, then default
> MAX open FD limit may occur. The best is to combine both.
>

That makes sense if the application is long lived and is continually
requesting and releasing resources, but that is not the case here - this
is a short lived app that makes a single request.
Note the "here" in my initial reply.

Cheers,
Kent.




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux