diff mbox

[4/6] hostmem-file: fix memory leak

Message ID 1456998223-12356-5-git-send-email-arei.gonglei@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gonglei (Arei) March 3, 2016, 9:43 a.m. UTC
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 backends/hostmem-file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Paolo Bonzini March 3, 2016, 11:19 a.m. UTC | #1
On 03/03/2016 10:43, Gonglei wrote:
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  backends/hostmem-file.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
> index fd59482..217f858 100644
> --- a/backends/hostmem-file.c
> +++ b/backends/hostmem-file.c
> @@ -51,11 +51,14 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
>      error_setg(errp, "-mem-path not supported on this host");
>  #else
>      if (!memory_region_size(&backend->mr)) {
> +        gchar *path;
>          backend->force_prealloc = mem_prealloc;
> +        path = object_get_canonical_path(OBJECT(backend));
>          memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
> -                                 object_get_canonical_path(OBJECT(backend)),
> +                                 path,
>                                   backend->size, fb->share,
>                                   fb->mem_path, errp);
> +        g_free(path);
>      }
>  #endif
>  }
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox

Patch

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index fd59482..217f858 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -51,11 +51,14 @@  file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
     error_setg(errp, "-mem-path not supported on this host");
 #else
     if (!memory_region_size(&backend->mr)) {
+        gchar *path;
         backend->force_prealloc = mem_prealloc;
+        path = object_get_canonical_path(OBJECT(backend));
         memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
-                                 object_get_canonical_path(OBJECT(backend)),
+                                 path,
                                  backend->size, fb->share,
                                  fb->mem_path, errp);
+        g_free(path);
     }
 #endif
 }