[libvirt] [PATCH] macvtap: plug memory leak for 802.1Qbh

Eric Blake eblake at redhat.com
Thu Oct 13 22:49:30 UTC 2011


Detected by Coverity.  Leak present since commit ca3b22b.

* src/util/macvtap.c (doPortProfileOp8021Qbh): Release device name.
---
getPhysfnDev allocates physfndev, but nothing freed it.
Pushing under the trivial rule.

 src/util/macvtap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/util/macvtap.c b/src/util/macvtap.c
index 9bf7fa6..a020c90 100644
--- a/src/util/macvtap.c
+++ b/src/util/macvtap.c
@@ -983,27 +983,27 @@ doPortProfileOp8021Qbh(const char *ifname,
 # ifndef IFLA_VF_PORT_MAX

     (void)ifname;
     (void)macaddr;
     (void)virtPort;
     (void)vm_uuid;
     (void)virtPortOp;
     macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
                  _("Kernel VF Port support was missing at compile time."));
     rc = 1;

 # else /* IFLA_VF_PORT_MAX */

-    char *physfndev;
+    char *physfndev = NULL;
     unsigned char hostuuid[VIR_UUID_BUFLEN];
     int32_t vf;
     bool nltarget_kernel = true;
     int ifindex;
     int vlanid = -1;

     rc = getPhysfnDev(ifname, &vf, &physfndev);
     if (rc)
         goto err_exit;

     if (ifaceGetIndex(true, physfndev, &ifindex) < 0) {
         rc = 1;
         goto err_exit;
@@ -1049,26 +1049,27 @@ doPortProfileOp8021Qbh(const char *ifname,
                                    NULL,
                                    NULL,
                                    vf,
                                    PORT_REQUEST_DISASSOCIATE);
         break;

     default:
         macvtapError(VIR_ERR_INTERNAL_ERROR,
                      _("operation type %d not supported"), virtPortOp);
         rc = 1;
     }

 err_exit:
+    VIR_FREE(physfndev);

 # endif /* IFLA_VF_PORT_MAX */

     return rc;
 }

 /**
  * vpAssociatePortProfile
  *
  * @macvtap_ifname: The name of the macvtap device
  * @virtPort: pointer to the object holding port profile parameters
  * @vmuuid : the UUID of the virtual machine
  * @vmOp : The VM operation (i.e., create, no-op)
-- 
1.7.4.4




More information about the libvir-list mailing list