On Thu, Nov 13, 2025 at 03:58:50PM -0600, Eric Blake via Libguestfs wrote:
> No need to re-strdup things in a loop of getline - since we are using
> popen to get the output in the first place, we can use the shell to
> hand us just the final line.
> 
> Signed-off-by: Eric Blake <[email protected]>
> ---
> 
> Even though the POSIX folks ruled today that our "ab"use of a
> getline() loop to determine the final line of du output was
> non-portable [1], I was still miffed at the malloc overhead that our
> workaround for rawhide glibc entailed.  So this is the result I came
> up with.
> 
> [1] https://www.austingroupbugs.net/bug_view_page.php?bug_id=1953
> 
>  plugins/linuxdisk/filesystem.c | 28 +++++++---------------------
>  1 file changed, 7 insertions(+), 21 deletions(-)
> 
> diff --git a/plugins/linuxdisk/filesystem.c b/plugins/linuxdisk/filesystem.c
> index 283af61a..aa4615e6 100644
> --- a/plugins/linuxdisk/filesystem.c
> +++ b/plugins/linuxdisk/filesystem.c
> @@ -148,7 +148,7 @@ create_filesystem (struct virtual_disk *disk)
>  static int64_t
>  estimate_size (void)
>  {
> -  CLEANUP_FREE char *command = NULL, *line = NULL, *lastline = NULL;
> +  CLEANUP_FREE char *command = NULL, *line = NULL;

Doh - this line...

> +  /* Should only be one line of input. */
> +  if (getline (&line, &len, fp) == -1 || ferror (fp)) {
>      nbdkit_error ("getline failed: %m");
>      pclose (fp);
> +    free (line);

...means that this addition is not only unnecessary, but a double-free
bug.  Good thing I waited for a review, rather than pushing right away.

>      return -1;

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
_______________________________________________
Libguestfs mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to