From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH] fix memory and descriptor leaks in grub_util_is_imsm
Date: Wed, 14 Aug 2013 17:35:32 +0200 [thread overview]
Message-ID: <520BA3C4.6070009@gmail.com> (raw)
In-Reply-To: <1374234795-24104-1-git-send-email-arvidjaar@gmail.com>
Go ahead.
On 19.07.2013 13:53, Andrey Borzenkov wrote:
> Descriptor leak caused warning from later vgs invocation. Fix memory
> leak (buffer was not always freed) while on it.
>
> Signed-off-by: Andrey Borzenkov <arvidjaar@gmail.com>
>
> ---
> util/getroot.c | 29 +++++++++++++++--------------
> 1 file changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/util/getroot.c b/util/getroot.c
> index 2ad8a55..b30a0d8 100644
> --- a/util/getroot.c
> +++ b/util/getroot.c
> @@ -1455,10 +1455,12 @@ out:
> static int
> grub_util_is_imsm (const char *os_dev)
> {
> - int try;
> + int retry;
> + int is_imsm = 0;
> + int container_seen = 0;
> const char *dev = os_dev;
>
> - for (try = 0; try < 2; try++)
> + do
> {
> char *argv[5];
> int fd;
> @@ -1467,6 +1469,8 @@ grub_util_is_imsm (const char *os_dev)
> char *buf = NULL;
> size_t len = 0;
>
> + retry = 0; /* We'll do one more pass if device is part of container */
> +
> /* execvp has inconvenient types, hence the casts. None of these
> strings will actually be modified. */
> argv[0] = (char *) "mdadm";
> @@ -1499,7 +1503,8 @@ grub_util_is_imsm (const char *os_dev)
>
> while (getline (&buf, &len, mdadm) > 0)
> {
> - if (strncmp (buf, "MD_CONTAINER=", sizeof ("MD_CONTAINER=") - 1) == 0)
> + if (strncmp (buf, "MD_CONTAINER=", sizeof ("MD_CONTAINER=") - 1) == 0
> + && !container_seen)
> {
> char *newdev, *ptr;
> newdev = xstrdup (buf + sizeof ("MD_CONTAINER=") - 1);
> @@ -1508,31 +1513,27 @@ grub_util_is_imsm (const char *os_dev)
> ptr[1] = 0;
> grub_util_info ("Container of %s is %s", dev, newdev);
> dev = newdev;
> - goto out;
> + container_seen = retry = 1;
> + break;
> }
> if (strncmp (buf, "MD_METADATA=imsm",
> sizeof ("MD_METADATA=imsm") - 1) == 0)
> {
> - close (fd);
> - waitpid (pid, NULL, 0);
> + is_imsm = 1;
> grub_util_info ("%s is imsm", dev);
> - if (dev != os_dev)
> - free ((void *) dev);
> - return 1;
> + break;
> }
> }
>
> free (buf);
> -
> - return 0;
> -
> - out:
> close (fd);
> waitpid (pid, NULL, 0);
> }
> + while (retry);
> +
> if (dev != os_dev)
> free ((void *) dev);
> - return 0;
> + return is_imsm;
> }
> #endif /* __linux__ */
>
>
prev parent reply other threads:[~2013-08-14 15:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-19 11:53 [PATCH] fix memory and descriptor leaks in grub_util_is_imsm Andrey Borzenkov
2013-08-14 15:35 ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
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=520BA3C4.6070009@gmail.com \
--to=phcoder@gmail.com \
--cc=grub-devel@gnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.