diff mbox

[1/3] exec: fix memory leak in find_max_supported_pagesize()

Message ID 152231458624.69730.1752893648612848392.stgit@bahia.lan (mailing list archive)
State New, archived
Headers show

Commit Message

Greg Kurz March 29, 2018, 9:09 a.m. UTC
The string returned by object_property_get_str() is dynamically allocated.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 exec.c |    1 +
 1 file changed, 1 insertion(+)

Comments

Cornelia Huck March 29, 2018, 9:18 a.m. UTC | #1
On Thu, 29 Mar 2018 11:09:46 +0200
Greg Kurz <groug@kaod.org> wrote:

> The string returned by object_property_get_str() is dynamically allocated.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
>  exec.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/exec.c b/exec.c
> index c09bd93df31e..02b1efebb7c3 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1495,6 +1495,7 @@ static int find_max_supported_pagesize(Object *obj, void *opaque)
>          mem_path = object_property_get_str(obj, "mem-path", NULL);
>          if (mem_path) {
>              long hpsize = qemu_mempath_getpagesize(mem_path);
> +            g_free(mem_path);
>              if (hpsize < *hpsize_min) {
>                  *hpsize_min = hpsize;
>              }
> 

Personally, I'd probably do the g_free() at the end of the if
(mem_path) branch, but this works as well.

Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Greg Kurz March 29, 2018, 9:44 a.m. UTC | #2
On Thu, 29 Mar 2018 11:18:31 +0200
Cornelia Huck <cohuck@redhat.com> wrote:

> On Thu, 29 Mar 2018 11:09:46 +0200
> Greg Kurz <groug@kaod.org> wrote:
> 
> > The string returned by object_property_get_str() is dynamically allocated.
> > 
> > Signed-off-by: Greg Kurz <groug@kaod.org>
> > ---
> >  exec.c |    1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/exec.c b/exec.c
> > index c09bd93df31e..02b1efebb7c3 100644
> > --- a/exec.c
> > +++ b/exec.c
> > @@ -1495,6 +1495,7 @@ static int find_max_supported_pagesize(Object *obj, void *opaque)
> >          mem_path = object_property_get_str(obj, "mem-path", NULL);
> >          if (mem_path) {
> >              long hpsize = qemu_mempath_getpagesize(mem_path);
> > +            g_free(mem_path);
> >              if (hpsize < *hpsize_min) {
> >                  *hpsize_min = hpsize;
> >              }
> >   
> 
> Personally, I'd probably do the g_free() at the end of the if
> (mem_path) branch, but this works as well.
> 

I usually prefer to free the string as soon as it isn't needed
anymore... matter of taste :)

> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Thomas Huth March 29, 2018, 11:47 a.m. UTC | #3
On 29.03.2018 11:09, Greg Kurz wrote:
> The string returned by object_property_get_str() is dynamically allocated.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
>  exec.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/exec.c b/exec.c
> index c09bd93df31e..02b1efebb7c3 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1495,6 +1495,7 @@ static int find_max_supported_pagesize(Object *obj, void *opaque)
>          mem_path = object_property_get_str(obj, "mem-path", NULL);
>          if (mem_path) {
>              long hpsize = qemu_mempath_getpagesize(mem_path);
> +            g_free(mem_path);
>              if (hpsize < *hpsize_min) {
>                  *hpsize_min = hpsize;
>              }
> 
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>
Eduardo Habkost April 3, 2018, 2:06 a.m. UTC | #4
On Thu, Mar 29, 2018 at 11:09:46AM +0200, Greg Kurz wrote:
> The string returned by object_property_get_str() is dynamically allocated.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>

Queued, thanks.
diff mbox

Patch

diff --git a/exec.c b/exec.c
index c09bd93df31e..02b1efebb7c3 100644
--- a/exec.c
+++ b/exec.c
@@ -1495,6 +1495,7 @@  static int find_max_supported_pagesize(Object *obj, void *opaque)
         mem_path = object_property_get_str(obj, "mem-path", NULL);
         if (mem_path) {
             long hpsize = qemu_mempath_getpagesize(mem_path);
+            g_free(mem_path);
             if (hpsize < *hpsize_min) {
                 *hpsize_min = hpsize;
             }