]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: node_device: use separate variables for parsing integers
authorJán Tomko <jtomko@redhat.com>
Tue, 30 May 2023 14:59:56 +0000 (16:59 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 1 Jun 2023 08:31:31 +0000 (10:31 +0200)
In virNodeDeviceGetSCSIHostCaps, there is a pattern of reusing
a tmp value and stealing the pointer.

But in two case it is not stolen. Use separate variables for them
to avoid mixing autofree with manual free() calls.

Fixes: 8a0cb5f73ade3900546718eabe70cb064c6bd22c
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/node_device_conf.c

index fcee9c027c06c3f4f9d6b63f6b0b31917c1476e5..81c9f2a9c877a1f35e5f0bdb46939da88c574a9a 100644 (file)
@@ -2857,29 +2857,32 @@ virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHost *scsi_host)
     }
 
     if (virVHBAIsVportCapable(NULL, scsi_host->host)) {
+        g_autofree char *max_vports = NULL;
+        g_autofree char *vports = NULL;
+
         scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
 
-        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
-                                     "max_npiv_vports"))) {
+        if (!(max_vports = virVHBAGetConfig(NULL, scsi_host->host,
+                                            "max_npiv_vports"))) {
             VIR_WARN("Failed to read max_npiv_vports for host%d",
                      scsi_host->host);
             goto cleanup;
         }
 
-        if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) {
-            VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp);
+        if (virStrToLong_i(max_vports, NULL, 10, &scsi_host->max_vports) < 0) {
+            VIR_WARN("Failed to parse value of max_npiv_vports '%s'", max_vports);
             goto cleanup;
         }
 
-        if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
-                                      "npiv_vports_inuse"))) {
+        if (!(vports = virVHBAGetConfig(NULL, scsi_host->host,
+                                        "npiv_vports_inuse"))) {
             VIR_WARN("Failed to read npiv_vports_inuse for host%d",
                      scsi_host->host);
             goto cleanup;
         }
 
-        if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) {
-            VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tmp);
+        if (virStrToLong_i(vports, NULL, 10, &scsi_host->vports) < 0) {
+            VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", vports);
             goto cleanup;
         }
     }