All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] qga: Fix memory leak in split_list
@ 2022-10-18  4:46 Miaoqian Lin
  2022-10-18  6:31 ` Philippe Mathieu-Daudé
  2022-10-18  6:32 ` Marc-André Lureau
  0 siblings, 2 replies; 4+ messages in thread
From: Miaoqian Lin @ 2022-10-18  4:46 UTC (permalink / raw)
  To: Michael Roth, Konstantin Kostiuk, qemu-devel; +Cc: linmq006

We should use g_strfreev to free the memory allocated by g_strsplit().
Use g_free() will cause a memory leak.

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 qga/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/main.c b/qga/main.c
index 5a9d8252e075..04902076b25d 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -934,7 +934,7 @@ static GList *split_list(const gchar *str, const gchar *delim)
     for (i = 0; strv[i]; i++) {
         list = g_list_prepend(list, strv[i]);
     }
-    g_free(strv);
+    g_strfreev(strv);
 
     return list;
 }
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] qga: Fix memory leak in split_list
  2022-10-18  4:46 [PATCH] qga: Fix memory leak in split_list Miaoqian Lin
@ 2022-10-18  6:31 ` Philippe Mathieu-Daudé
  2022-10-18  6:32 ` Marc-André Lureau
  1 sibling, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-10-18  6:31 UTC (permalink / raw)
  To: Miaoqian Lin, QEMU Trivial, Marc-André Lureau
  Cc: Michael Roth, qemu-devel, Konstantin Kostiuk, Denis V. Lunev

On 18/10/22 06:46, Miaoqian Lin wrote:
> We should use g_strfreev to free the memory allocated by g_strsplit().
> Use g_free() will cause a memory leak.
> 
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>   qga/main.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qga/main.c b/qga/main.c
> index 5a9d8252e075..04902076b25d 100644
> --- a/qga/main.c
> +++ b/qga/main.c
> @@ -934,7 +934,7 @@ static GList *split_list(const gchar *str, const gchar *delim)
>       for (i = 0; strv[i]; i++) {
>           list = g_list_prepend(list, strv[i]);
>       }
> -    g_free(strv);
> +    g_strfreev(strv);
>   
>       return list;
>   }

Fixes: 4bca81ceed ("qga: make split_list() return allocated strings")
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] qga: Fix memory leak in split_list
  2022-10-18  4:46 [PATCH] qga: Fix memory leak in split_list Miaoqian Lin
  2022-10-18  6:31 ` Philippe Mathieu-Daudé
@ 2022-10-18  6:32 ` Marc-André Lureau
  2022-10-18  6:42   ` Miaoqian Lin
  1 sibling, 1 reply; 4+ messages in thread
From: Marc-André Lureau @ 2022-10-18  6:32 UTC (permalink / raw)
  To: Miaoqian Lin; +Cc: Michael Roth, Konstantin Kostiuk, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 774 bytes --]

Hi

On Tue, Oct 18, 2022 at 8:47 AM Miaoqian Lin <linmq006@gmail.com> wrote:

> We should use g_strfreev to free the memory allocated by g_strsplit().
> Use g_free() will cause a memory leak.
>
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  qga/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/qga/main.c b/qga/main.c
> index 5a9d8252e075..04902076b25d 100644
> --- a/qga/main.c
> +++ b/qga/main.c
> @@ -934,7 +934,7 @@ static GList *split_list(const gchar *str, const gchar
> *delim)
>      for (i = 0; strv[i]; i++) {
>          list = g_list_prepend(list, strv[i]);
>      }
> -    g_free(strv);
> +    g_strfreev(strv);
>

No, this is intentional. We are building a list of allocated strings, we
shouldn't free those.

thanks

[-- Attachment #2: Type: text/html, Size: 1264 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] qga: Fix memory leak in split_list
  2022-10-18  6:32 ` Marc-André Lureau
@ 2022-10-18  6:42   ` Miaoqian Lin
  0 siblings, 0 replies; 4+ messages in thread
From: Miaoqian Lin @ 2022-10-18  6:42 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: Michael Roth, Konstantin Kostiuk, qemu-devel

Hi,

On 2022/10/18 14:32, Marc-André Lureau wrote:
> Hi
>
> On Tue, Oct 18, 2022 at 8:47 AM Miaoqian Lin <linmq006@gmail.com> wrote:
>
>     We should use g_strfreev to free the memory allocated by g_strsplit().
>     Use g_free() will cause a memory leak.
>
>     Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
>     ---
>      qga/main.c | 2 +-
>      1 file changed, 1 insertion(+), 1 deletion(-)
>
>     diff --git a/qga/main.c b/qga/main.c
>     index 5a9d8252e075..04902076b25d 100644
>     --- a/qga/main.c
>     +++ b/qga/main.c
>     @@ -934,7 +934,7 @@ static GList *split_list(const gchar *str, const gchar *delim)
>          for (i = 0; strv[i]; i++) {
>              list = g_list_prepend(list, strv[i]);
>          }
>     -    g_free(strv);
>     +    g_strfreev(strv);
>
>
> No, this is intentional. We are building a list of allocated strings, we shouldn't free those.
>  

I get it. Thanks for your response. Sorry for the mistake.


> thanks


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-18  7:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18  4:46 [PATCH] qga: Fix memory leak in split_list Miaoqian Lin
2022-10-18  6:31 ` Philippe Mathieu-Daudé
2022-10-18  6:32 ` Marc-André Lureau
2022-10-18  6:42   ` Miaoqian Lin

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.