]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libxl: use init and dispose functions with libxl_physinfo
authorJim Fehlig <jfehlig@suse.com>
Wed, 1 Feb 2017 03:07:30 +0000 (20:07 -0700)
committerJim Fehlig <jfehlig@suse.com>
Wed, 8 Feb 2017 16:12:00 +0000 (09:12 -0700)
The typical pattern when calling libxl functions that populate a
structure is

  libxl_foo foo;
  libxl_foo_init(&foo);
  libxl_get_foo(ctx, &foo);
  ...
  libxl_foo_dispose(&foo);

Fix several instances of libxl_physinfo missing the init and
dispose calls.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
src/libxl/libxl_capabilities.c
src/libxl/libxl_conf.c
src/libxl/libxl_driver.c

index a1c0a8775a677083c4cb12bbbe2792ad6fd861e7..2bbd2d1b4f4d92586b4a2ff7bc06d868754820ca 100644 (file)
@@ -211,27 +211,33 @@ libxlCapsInitHost(libxl_ctx *ctx, virCapsPtr caps)
     const libxl_version_info *ver_info;
     enum libxlHwcapVersion version;
     libxl_physinfo phy_info;
+    int ret = -1;
 
+    libxl_physinfo_init(&phy_info);
     if (libxl_get_physinfo(ctx, &phy_info) != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Failed to get node physical info from libxenlight"));
-        return -1;
+        goto cleanup;
     }
 
     if ((ver_info = libxl_get_version_info(ctx)) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Failed to get version info from libxenlight"));
-        return -1;
+        goto cleanup;
     }
 
     version = (ver_info->xen_version_minor >= 7);
     if (libxlCapsInitCPU(caps, &phy_info, version) < 0)
-        return -1;
+        goto cleanup;
 
     if (virCapabilitiesSetNetPrefix(caps, LIBXL_GENERATED_PREFIX_XEN) < 0)
-        return -1;
+        goto cleanup;
 
-    return 0;
+    ret = 0;
+
+ cleanup:
+    libxl_physinfo_dispose(&phy_info);
+    return ret;
 }
 
 static int
index ee1e63919dace1096b12e49fd8205abb72599a85..28b05e1ce4d802d4ccd71ebb68e167baf1deaabd 100644 (file)
@@ -1943,6 +1943,7 @@ libxlDriverNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
     libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
     int ret = -1;
 
+    libxl_physinfo_init(&phy_info);
     if (libxl_get_physinfo(cfg->ctx, &phy_info)) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("libxl_get_physinfo_info failed"));
@@ -1967,6 +1968,7 @@ libxlDriverNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
     ret = 0;
 
  cleanup:
+    libxl_physinfo_dispose(&phy_info);
     virObjectUnref(cfg);
     return ret;
 }
index 3a69720a196b2a43f7dc25c0638418220c711720..38ad91e94fb743970045eb3f537c8e0299c45893 100644 (file)
@@ -4283,6 +4283,7 @@ libxlNodeGetFreeMemory(virConnectPtr conn)
     libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
     unsigned long long ret = 0;
 
+    libxl_physinfo_init(&phy_info);
     if (virNodeGetFreeMemoryEnsureACL(conn) < 0)
         goto cleanup;
 
@@ -4295,6 +4296,7 @@ libxlNodeGetFreeMemory(virConnectPtr conn)
     ret = phy_info.free_pages * cfg->verInfo->pagesize;
 
  cleanup:
+    libxl_physinfo_dispose(&phy_info);
     virObjectUnref(cfg);
     return ret;
 }