lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 9 Nov 2023 13:50:02 +0100
From:   Linus Walleij <linus.walleij@...aro.org>
To:     Kent Gibson <warthog618@...il.com>
Cc:     heminhong <heminhong@...inos.cn>, brgl@...ev.pl, andy@...nel.org,
        linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] tools/gpio: prevent resource leak

On Thu, Nov 9, 2023 at 1:36 PM Kent Gibson <warthog618@...il.com> 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.

Yup. And this is one of the reasons why we have the character device
in the first place.

The character device gets released and all GPIOs are released
if the program crashes.

You can imagine what happens with the sysfs ABI if a bash
script crashes halfway through some complex allocating and
banging GPIOs left and right. Not good at all.

Yours,
Linus Walleij

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ