* [PATCH] cutils: fix memory leak in get_relocated_path()
@ 2021-04-12 17:02 Stefano Garzarella
2021-04-13 10:59 ` Philippe Mathieu-Daudé
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Stefano Garzarella @ 2021-04-12 17:02 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Alex Bennée, Philippe Mathieu-Daudé
get_relocated_path() allocates a GString object and returns the
character data (C string) to the caller without freeing the memory
allocated for that object as reported by valgrind:
24 bytes in 1 blocks are definitely lost in loss record 2,805 of 6,532
at 0x4839809: malloc (vg_replace_malloc.c:307)
by 0x55AABB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
by 0x55C2481: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
by 0x55C4827: g_string_sized_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
by 0x55C4CEA: g_string_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
by 0x906314: get_relocated_path (cutils.c:1036)
by 0x6E1F77: qemu_read_default_config_file (vl.c:2122)
by 0x6E1F77: qemu_init (vl.c:2687)
by 0x3E3AF8: main (main.c:49)
Let's use g_string_free(gstring, false) to free only the GString object
and transfer the ownership of the character data to the caller.
Fixes: f4f5ed2cbd ("cutils: introduce get_relocated_path")
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
util/cutils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/util/cutils.c b/util/cutils.c
index ee908486da..c9b91e7535 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir)
assert(G_IS_DIR_SEPARATOR(dir[-1]));
g_string_append(result, dir - 1);
}
- return result->str;
+ return g_string_free(result, false);
}
--
2.30.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] cutils: fix memory leak in get_relocated_path()
2021-04-12 17:02 [PATCH] cutils: fix memory leak in get_relocated_path() Stefano Garzarella
@ 2021-04-13 10:59 ` Philippe Mathieu-Daudé
2021-04-13 11:47 ` Stefano Garzarella
2021-04-14 7:32 ` Marc-André Lureau
2021-05-10 15:57 ` Stefano Garzarella
2 siblings, 1 reply; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-04-13 10:59 UTC (permalink / raw)
To: Stefano Garzarella, qemu-devel; +Cc: Paolo Bonzini, Alex Bennée
Is this fix aiming at 6.0 release?
On 4/12/21 7:02 PM, Stefano Garzarella wrote:
> get_relocated_path() allocates a GString object and returns the
> character data (C string) to the caller without freeing the memory
> allocated for that object as reported by valgrind:
>
> 24 bytes in 1 blocks are definitely lost in loss record 2,805 of 6,532
> at 0x4839809: malloc (vg_replace_malloc.c:307)
> by 0x55AABB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x55C2481: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x55C4827: g_string_sized_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x55C4CEA: g_string_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x906314: get_relocated_path (cutils.c:1036)
> by 0x6E1F77: qemu_read_default_config_file (vl.c:2122)
> by 0x6E1F77: qemu_init (vl.c:2687)
> by 0x3E3AF8: main (main.c:49)
>
> Let's use g_string_free(gstring, false) to free only the GString object
> and transfer the ownership of the character data to the caller.
>
> Fixes: f4f5ed2cbd ("cutils: introduce get_relocated_path")
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
> util/cutils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/util/cutils.c b/util/cutils.c
> index ee908486da..c9b91e7535 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir)
> assert(G_IS_DIR_SEPARATOR(dir[-1]));
> g_string_append(result, dir - 1);
> }
> - return result->str;
> + return g_string_free(result, false);
> }
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cutils: fix memory leak in get_relocated_path()
2021-04-13 10:59 ` Philippe Mathieu-Daudé
@ 2021-04-13 11:47 ` Stefano Garzarella
2021-04-13 16:03 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 8+ messages in thread
From: Stefano Garzarella @ 2021-04-13 11:47 UTC (permalink / raw)
To: Philippe Mathieu-Daudé; +Cc: Paolo Bonzini, Alex Bennée, qemu-devel
On Tue, Apr 13, 2021 at 12:59:36PM +0200, Philippe Mathieu-Daudé wrote:
>Is this fix aiming at 6.0 release?
The leak is minimal, but the fix is very simple.
So, I think it can go if someone has a pull request to send with other
patches, but I'm not sure with which tree.
Thanks,
Stefano
>
>On 4/12/21 7:02 PM, Stefano Garzarella wrote:
>> get_relocated_path() allocates a GString object and returns the
>> character data (C string) to the caller without freeing the memory
>> allocated for that object as reported by valgrind:
>>
>> 24 bytes in 1 blocks are definitely lost in loss record 2,805 of 6,532
>> at 0x4839809: malloc (vg_replace_malloc.c:307)
>> by 0x55AABB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
>> by 0x55C2481: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
>> by 0x55C4827: g_string_sized_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
>> by 0x55C4CEA: g_string_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
>> by 0x906314: get_relocated_path (cutils.c:1036)
>> by 0x6E1F77: qemu_read_default_config_file (vl.c:2122)
>> by 0x6E1F77: qemu_init (vl.c:2687)
>> by 0x3E3AF8: main (main.c:49)
>>
>> Let's use g_string_free(gstring, false) to free only the GString object
>> and transfer the ownership of the character data to the caller.
>>
>> Fixes: f4f5ed2cbd ("cutils: introduce get_relocated_path")
>> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>> ---
>> util/cutils.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/util/cutils.c b/util/cutils.c
>> index ee908486da..c9b91e7535 100644
>> --- a/util/cutils.c
>> +++ b/util/cutils.c
>> @@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir)
>> assert(G_IS_DIR_SEPARATOR(dir[-1]));
>> g_string_append(result, dir - 1);
>> }
>> - return result->str;
>> + return g_string_free(result, false);
>> }
>>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cutils: fix memory leak in get_relocated_path()
2021-04-13 11:47 ` Stefano Garzarella
@ 2021-04-13 16:03 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-04-13 16:03 UTC (permalink / raw)
To: Stefano Garzarella
Cc: Paolo Bonzini, Daniel P . Berrange, Alex Bennée, qemu-devel,
Marc-André Lureau
On 4/13/21 1:47 PM, Stefano Garzarella wrote:
> On Tue, Apr 13, 2021 at 12:59:36PM +0200, Philippe Mathieu-Daudé wrote:
>> Is this fix aiming at 6.0 release?
>
> The leak is minimal, but the fix is very simple.
> So, I think it can go if someone has a pull request to send with other
> patches, but I'm not sure with which tree.
I'd say Paolo...
Cc'ing Daniel/Marc-André who have a good GLib understanding.
>
> Thanks,
> Stefano
>
>>
>> On 4/12/21 7:02 PM, Stefano Garzarella wrote:
>>> get_relocated_path() allocates a GString object and returns the
>>> character data (C string) to the caller without freeing the memory
>>> allocated for that object as reported by valgrind:
>>>
>>> 24 bytes in 1 blocks are definitely lost in loss record 2,805 of 6,532
>>> at 0x4839809: malloc (vg_replace_malloc.c:307)
>>> by 0x55AABB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
>>> by 0x55C2481: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
>>> by 0x55C4827: g_string_sized_new (in
>>> /usr/lib64/libglib-2.0.so.0.6600.8)
>>> by 0x55C4CEA: g_string_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
>>> by 0x906314: get_relocated_path (cutils.c:1036)
>>> by 0x6E1F77: qemu_read_default_config_file (vl.c:2122)
>>> by 0x6E1F77: qemu_init (vl.c:2687)
>>> by 0x3E3AF8: main (main.c:49)
>>>
>>> Let's use g_string_free(gstring, false) to free only the GString object
>>> and transfer the ownership of the character data to the caller.
>>>
>>> Fixes: f4f5ed2cbd ("cutils: introduce get_relocated_path")
>>> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>>> ---
>>> util/cutils.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/util/cutils.c b/util/cutils.c
>>> index ee908486da..c9b91e7535 100644
>>> --- a/util/cutils.c
>>> +++ b/util/cutils.c
>>> @@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir)
>>> assert(G_IS_DIR_SEPARATOR(dir[-1]));
>>> g_string_append(result, dir - 1);
>>> }
>>> - return result->str;
>>> + return g_string_free(result, false);
>>> }
>>>
>>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cutils: fix memory leak in get_relocated_path()
2021-04-12 17:02 [PATCH] cutils: fix memory leak in get_relocated_path() Stefano Garzarella
2021-04-13 10:59 ` Philippe Mathieu-Daudé
@ 2021-04-14 7:32 ` Marc-André Lureau
2021-05-10 15:57 ` Stefano Garzarella
2 siblings, 0 replies; 8+ messages in thread
From: Marc-André Lureau @ 2021-04-14 7:32 UTC (permalink / raw)
To: Stefano Garzarella
Cc: Paolo Bonzini, Alex Bennée, QEMU, Philippe Mathieu-Daudé
[-- Attachment #1: Type: text/plain, Size: 1773 bytes --]
On Mon, Apr 12, 2021 at 9:06 PM Stefano Garzarella <sgarzare@redhat.com>
wrote:
> get_relocated_path() allocates a GString object and returns the
> character data (C string) to the caller without freeing the memory
> allocated for that object as reported by valgrind:
>
> 24 bytes in 1 blocks are definitely lost in loss record 2,805 of 6,532
> at 0x4839809: malloc (vg_replace_malloc.c:307)
> by 0x55AABB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x55C2481: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x55C4827: g_string_sized_new (in
> /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x55C4CEA: g_string_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x906314: get_relocated_path (cutils.c:1036)
> by 0x6E1F77: qemu_read_default_config_file (vl.c:2122)
> by 0x6E1F77: qemu_init (vl.c:2687)
> by 0x3E3AF8: main (main.c:49)
>
> Let's use g_string_free(gstring, false) to free only the GString object
> and transfer the ownership of the character data to the caller.
>
> Fixes: f4f5ed2cbd ("cutils: introduce get_relocated_path")
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
> util/cutils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/util/cutils.c b/util/cutils.c
> index ee908486da..c9b91e7535 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir)
> assert(G_IS_DIR_SEPARATOR(dir[-1]));
> g_string_append(result, dir - 1);
> }
> - return result->str;
> + return g_string_free(result, false);
> }
> --
> 2.30.2
>
>
>
--
Marc-André Lureau
[-- Attachment #2: Type: text/html, Size: 2593 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cutils: fix memory leak in get_relocated_path()
2021-04-12 17:02 [PATCH] cutils: fix memory leak in get_relocated_path() Stefano Garzarella
2021-04-13 10:59 ` Philippe Mathieu-Daudé
2021-04-14 7:32 ` Marc-André Lureau
@ 2021-05-10 15:57 ` Stefano Garzarella
2021-05-11 5:38 ` Markus Armbruster
2 siblings, 1 reply; 8+ messages in thread
From: Stefano Garzarella @ 2021-05-10 15:57 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Alex Bennée, qemu-devel, Philippe Mathieu-Daudé
Ping :-)
Should I resend for 6.1?
Thanks
Stefano
On Mon, Apr 12, 2021 at 07:02:55PM +0200, Stefano Garzarella wrote:
>get_relocated_path() allocates a GString object and returns the
>character data (C string) to the caller without freeing the memory
>allocated for that object as reported by valgrind:
>
> 24 bytes in 1 blocks are definitely lost in loss record 2,805 of 6,532
> at 0x4839809: malloc (vg_replace_malloc.c:307)
> by 0x55AABB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x55C2481: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x55C4827: g_string_sized_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x55C4CEA: g_string_new (in /usr/lib64/libglib-2.0.so.0.6600.8)
> by 0x906314: get_relocated_path (cutils.c:1036)
> by 0x6E1F77: qemu_read_default_config_file (vl.c:2122)
> by 0x6E1F77: qemu_init (vl.c:2687)
> by 0x3E3AF8: main (main.c:49)
>
>Let's use g_string_free(gstring, false) to free only the GString object
>and transfer the ownership of the character data to the caller.
>
>Fixes: f4f5ed2cbd ("cutils: introduce get_relocated_path")
>Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>---
> util/cutils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/util/cutils.c b/util/cutils.c
>index ee908486da..c9b91e7535 100644
>--- a/util/cutils.c
>+++ b/util/cutils.c
>@@ -1055,5 +1055,5 @@ char *get_relocated_path(const char *dir)
> assert(G_IS_DIR_SEPARATOR(dir[-1]));
> g_string_append(result, dir - 1);
> }
>- return result->str;
>+ return g_string_free(result, false);
> }
>--
>2.30.2
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cutils: fix memory leak in get_relocated_path()
2021-05-10 15:57 ` Stefano Garzarella
@ 2021-05-11 5:38 ` Markus Armbruster
2021-05-13 16:08 ` Laurent Vivier
0 siblings, 1 reply; 8+ messages in thread
From: Markus Armbruster @ 2021-05-11 5:38 UTC (permalink / raw)
To: Stefano Garzarella
Cc: qemu-trivial, Paolo Bonzini, Alex Bennée, qemu-devel,
Philippe Mathieu-Daudé
Stefano Garzarella <sgarzare@redhat.com> writes:
> Ping :-)
>
> Should I resend for 6.1?
I'm cc'ing qemu-trivial.
For good measure:
Reviewed-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cutils: fix memory leak in get_relocated_path()
2021-05-11 5:38 ` Markus Armbruster
@ 2021-05-13 16:08 ` Laurent Vivier
0 siblings, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2021-05-13 16:08 UTC (permalink / raw)
To: Markus Armbruster, Stefano Garzarella
Cc: qemu-trivial, Paolo Bonzini, Alex Bennée, qemu-devel,
Philippe Mathieu-Daudé
Le 11/05/2021 à 07:38, Markus Armbruster a écrit :
> Stefano Garzarella <sgarzare@redhat.com> writes:
>
>> Ping :-)
>>
>> Should I resend for 6.1?
>
> I'm cc'ing qemu-trivial.
>
> For good measure:
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>
>
Applied to my trivial-patches branch.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-05-13 16:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 17:02 [PATCH] cutils: fix memory leak in get_relocated_path() Stefano Garzarella
2021-04-13 10:59 ` Philippe Mathieu-Daudé
2021-04-13 11:47 ` Stefano Garzarella
2021-04-13 16:03 ` Philippe Mathieu-Daudé
2021-04-14 7:32 ` Marc-André Lureau
2021-05-10 15:57 ` Stefano Garzarella
2021-05-11 5:38 ` Markus Armbruster
2021-05-13 16:08 ` Laurent Vivier
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).