Re: [PATCH] nodedevmdevctltest: Fix two memleaks

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

 



On Mon, Feb 26, 2024 at 13:22:37 +0100, Michal Privoznik wrote:
> There are two memleaks inside of nodedevmdevctltest:
> 
> 1) In the testCommandDryRunCallback() - when appending lines to
>    stdinbuf the pointer is overwritten without freeing the old
>    memory it pointed to.
> 
> 2) In testMdevctlModify() the livecmd variable is reused and
>    since its marked as g_autoptr() the first use leaks.
> 

Please add the "Fixes" tag:

> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---
>  tests/nodedevmdevctltest.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
> index de688c982e..827036fa74 100644
> --- a/tests/nodedevmdevctltest.c
> +++ b/tests/nodedevmdevctltest.c
> @@ -33,10 +33,13 @@ testCommandDryRunCallback(const char *const*args G_GNUC_UNUSED,
>  {
>      char **stdinbuf = opaque;
>  
> -    if (*stdinbuf)
> -        *stdinbuf = g_strconcat(*stdinbuf, "\n", input, NULL);
> -    else
> +    if (*stdinbuf) {

Alternatively:
            g_autofree char *oldbuf = g_steal_pointer(stdinbuf);
            *stdinbuf = g_strconcat(oldbuf, "\n", input, NULL);


> +        char *new = g_strconcat(*stdinbuf, "\n", input, NULL);
> +        VIR_FREE(*stdinbuf);
> +        *stdinbuf = g_steal_pointer(&new);
> +    } else {
>          *stdinbuf = g_strdup(input);
> +    }
>  }

Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux