[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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





On 10/13/11 3:49 PM, "Eric Blake" <eblake redhat com> wrote:

> 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);

Thanks for catching this Eric

Actually looks like physfndev is conditionally allocated in getPhysfnDev
Its better to modify getPhysfnDev to allocate physfndev every time.


I ACK this patch with the additional change below (looks ok ?)

diff --git a/src/util/macvtap.c b/src/util/macvtap.c
index a020c90..b50b7d2 100644
--- a/src/util/macvtap.c
+++ b/src/util/macvtap.c
@@ -964,7 +964,7 @@ getPhysfnDev(const char *linkdev,
          */
 
         *vf = PORT_SELF_VF;
-        *physfndev = (char *)linkdev;
+        *physfndev = strdup(linkdev);
     }
 
     return rc;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]