]> xenbits.xensource.com Git - libvirt.git/commitdiff
Delete udevFreeIfaceDef function in udev interface driver
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 29 Apr 2013 17:10:57 +0000 (18:10 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 9 May 2013 11:34:26 +0000 (12:34 +0100)
The udevFreeIfaceDef function in the udev interface driver
just duplicates code from virInterfaceDefFree. Delete it
and call the standard API instead.

Fix the udevGetIfaceDefVlan method so that it doesn't
store pointers to the middle of a malloc'd memory
area.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/interface/interface_backend_udev.c

index 7daad16b8ec34fa8f8fe187bef0b597732a11468..beee90a369fe01463d76d0a0b5f36912770e8db1 100644 (file)
@@ -543,44 +543,6 @@ udevBridgeScanDirFilter(const struct dirent *entry)
     return 1;
 }
 
-/**
- * Frees any memory allocated by udevGetIfaceDef()
- *
- * @param ifacedef - interface to free and cleanup
- */
-static void
-udevFreeIfaceDef(virInterfaceDef *ifacedef)
-{
-    int i;
-
-    if (!ifacedef)
-        return;
-
-    if (ifacedef->type == VIR_INTERFACE_TYPE_BOND) {
-        VIR_FREE(ifacedef->data.bond.target);
-        for (i = 0; i < ifacedef->data.bond.nbItf; i++) {
-            udevFreeIfaceDef(ifacedef->data.bond.itf[i]);
-        }
-        VIR_FREE(ifacedef->data.bond.itf);
-    }
-
-    if (ifacedef->type == VIR_INTERFACE_TYPE_BRIDGE) {
-        VIR_FREE(ifacedef->data.bridge.delay);
-        for (i = 0; i < ifacedef->data.bridge.nbItf; i++) {
-            udevFreeIfaceDef(ifacedef->data.bridge.itf[i]);
-        }
-        VIR_FREE(ifacedef->data.bridge.itf);
-    }
-
-    if (ifacedef->type == VIR_INTERFACE_TYPE_VLAN) {
-        VIR_FREE(ifacedef->data.vlan.devname);
-    }
-
-    VIR_FREE(ifacedef->mac);
-    VIR_FREE(ifacedef->name);
-
-    VIR_FREE(ifacedef);
-}
 
 static int
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
@@ -935,36 +897,29 @@ udevGetIfaceDefVlan(struct udev *udev ATTRIBUTE_UNUSED,
                     const char *name,
                     virInterfaceDef *ifacedef)
 {
-    char *vid;
-    char *vlan_parent_dev = NULL;
-
-    vlan_parent_dev = strdup(name);
-    if (!vlan_parent_dev) {
-        virReportOOMError();
-        goto cleanup;
-    }
+    const char *vid;
 
     /* Find the DEVICE.VID again */
-    vid = strrchr(vlan_parent_dev, '.');
+    vid = strrchr(name, '.');
     if (!vid) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                _("failed to find the VID for the VLAN device '%s'"),
-                name);
-        goto cleanup;
-        }
-
-    /* Replace the dot with a NULL so we can have the device and VID */
-    vid[0] = '\0';
-    vid++;
+                       _("failed to find the VID for the VLAN device '%s'"),
+                       name);
+        return -1;
+    }
 
     /* Set the VLAN specifics */
-    ifacedef->data.vlan.tag = vid;
-    ifacedef->data.vlan.devname = vlan_parent_dev;
+    if (VIR_STRDUP(ifacedef->data.vlan.tag, vid + 1) < 0)
+        goto cleanup;
+    if (VIR_STRNDUP(ifacedef->data.vlan.devname,
+                    name, (vid - name)) < 0)
+        goto cleanup;
 
     return 0;
 
 cleanup:
-    VIR_FREE(vlan_parent_dev);
+    VIR_FREE(ifacedef->data.vlan.tag);
+    VIR_FREE(ifacedef->data.vlan.devname);
 
     return -1;
 }
@@ -1081,7 +1036,7 @@ udevGetIfaceDef(struct udev *udev, const char *name)
 cleanup:
     udev_device_unref(dev);
 
-    udevFreeIfaceDef(ifacedef);
+    virInterfaceDefFree(ifacedef);
 
     return NULL;
 }
@@ -1102,15 +1057,12 @@ udevInterfaceGetXMLDesc(virInterfacePtr ifinfo,
      */
     ifacedef = udevGetIfaceDef(udev, ifinfo->name);
 
-    /* We've already printed by it happened */
     if (!ifacedef)
         goto err;
 
-    /* Convert our interface to XML */
     xmlstr = virInterfaceDefFormat(ifacedef);
 
-    /* Recursively free our interface structures and free the children too */
-    udevFreeIfaceDef(ifacedef);
+    virInterfaceDefFree(ifacedef);
 
 err:
     /* decrement our udev ptr */