openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Joel Stanley <joel@jms.id.au>
Cc: Andrew Jeffery <andrew@aj.id.au>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	OpenBMC Maillist <openbmc@lists.ozlabs.org>,
	Zev Weiss <zweiss@equinix.com>
Subject: Re: [libgpiod PATCH 1/7] tools: Clean up scandir memory allocations
Date: Tue, 8 Feb 2022 12:21:43 +0100	[thread overview]
Message-ID: <CAMRc=MfYH=YuFaV-pX0weM5o+i7u7gkQ7d7qg2j-XK2EoN1BkA@mail.gmail.com> (raw)
In-Reply-To: <20220203042134.68425-2-joel@jms.id.au>

On Thu, Feb 3, 2022 at 5:22 AM Joel Stanley <joel@jms.id.au> wrote:
>
> The code copied from gpiofind didn't free the memory from scandir.
>
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
>  tools/tools-common.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/tools/tools-common.c b/tools/tools-common.c
> index 0dc3d52668d7..c83e68a2c1e4 100644
> --- a/tools/tools-common.c
> +++ b/tools/tools-common.c
> @@ -190,12 +190,17 @@ struct gpiod_chip *chip_by_line_name(const char *name)
>
>                         die_perror("unable to open %s", entries[i]->d_name);
>                 }
> +               free(entries[i]);
>
>                 offset = gpiod_chip_find_line(chip, name);
> -               if (offset >= 0)
> +               if (offset >= 0) {
> +                       free(entries);
>                         return chip;
> +               }
> +               gpiod_chip_unref(chip);
>         }
>
> +       free(entries);
>         return NULL;
>  }
>
> --
> 2.34.1
>

Good catch! It doesn't come up with gpiodetect which is what I tested
with valgrind but does show up for gpiofind and gpioinfo. This patch
however doesn't apply on the current master. Also: I don't really want
new features for the v1.6.x series and we're heavily reworking the
interface. Current version is in the next/libgpiod-2.0 branch but I
should be posting a new version with reworked test suite later this
week. How about working on this feature for the new API right away and
make it part of libgpiod starting with v2.0?

Bart

  reply	other threads:[~2022-02-08 11:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03  4:21 [libgpiod PATCH 0/7] tools: Add by-name support Joel Stanley
2022-02-03  4:21 ` [libgpiod PATCH 1/7] tools: Clean up scandir memory allocations Joel Stanley
2022-02-08 11:21   ` Bartosz Golaszewski [this message]
2022-02-03  4:21 ` [libgpiod PATCH 2/7] tools: Add line name to offset lookup helper Joel Stanley
2022-02-03  4:21 ` [libgpiod PATCH 3/7] tools: Add value support to line name lookup Joel Stanley
2022-02-03  8:37   ` Zev Weiss
2022-02-03  4:21 ` [libgpiod PATCH 4/7] tools: gpioget: Add by-name support Joel Stanley
2022-02-03  8:37   ` Zev Weiss
2022-02-03  4:21 ` [libgpiod PATCH 5/7] tools: gpioset: " Joel Stanley
2022-02-03  8:37   ` Zev Weiss
2022-02-03  4:21 ` [libgpiod PATCH 6/7] gpio-tools-test: Add gpioset --by-name tests Joel Stanley
2022-02-03  4:21 ` [libgpiod PATCH 7/7] gpio-tools-test: Add gpioget " Joel Stanley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMRc=MfYH=YuFaV-pX0weM5o+i7u7gkQ7d7qg2j-XK2EoN1BkA@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=andrew@aj.id.au \
    --cc=joel@jms.id.au \
    --cc=linux-gpio@vger.kernel.org \
    --cc=openbmc@lists.ozlabs.org \
    --cc=zweiss@equinix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).