diff mbox

[v6,11/13] libxl: fix memory leak in libxl__colo_save_setup

Message ID 1505224098-19330-12-git-send-email-al1img@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Oleksandr Grytsov Sept. 12, 2017, 1:48 p.m. UTC
From: Oleksandr Grytsov <oleksandr_grytsov@epam.com>

Getting nic list in case userspace proxy is called
without freeing. The fix is to use cds->nics to
keep nic list. cds->nics will be freed in
devices_teardown_cb.

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
---
 tools/libxl/libxl_colo_save.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Wei Liu Sept. 12, 2017, 4:10 p.m. UTC | #1
On Tue, Sep 12, 2017 at 04:48:16PM +0300, Oleksandr Grytsov wrote:
> From: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
> 
> Getting nic list in case userspace proxy is called
> without freeing. The fix is to use cds->nics to
> keep nic list. cds->nics will be freed in
> devices_teardown_cb.
> 
> Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>
diff mbox

Patch

diff --git a/tools/libxl/libxl_colo_save.c b/tools/libxl/libxl_colo_save.c
index bf68198..43f7dbe 100644
--- a/tools/libxl/libxl_colo_save.c
+++ b/tools/libxl/libxl_colo_save.c
@@ -86,7 +86,6 @@  void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css)
     libxl__checkpoint_devices_state *const cds = &dss->cds;
     libxl__srm_save_autogen_callbacks *const callbacks =
         &dss->sws.shs.callbacks.save.a;
-    libxl_device_nic *nics;
 
     STATE_AO_GC(dss->ao);
 
@@ -122,10 +121,12 @@  void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css)
         cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VBD);
 
         /* Use this args we can connect to qemu colo-compare */
-        nics = libxl__device_list(gc, &libxl__nic_devtype,
-                                  cds->domid, "vif", &cds->num_nics);
-        css->cps.checkpoint_host = nics->colo_checkpoint_host;
-        css->cps.checkpoint_port = nics->colo_checkpoint_port;
+        cds->nics = libxl__device_list(gc, &libxl__nic_devtype,
+                                       cds->domid, "vif", &cds->num_nics);
+        if (cds->num_nics > 0) {
+            css->cps.checkpoint_host = cds->nics[0].colo_checkpoint_host;
+            css->cps.checkpoint_port = cds->nics[0].colo_checkpoint_port;
+        }
     } else {
         cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VIF) |
                                  (1 << LIBXL__DEVICE_KIND_VBD);