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

Re: [libvirt] [PATCH] virsh: Call virDomainFree in cmdDomFSTrim



On 04/02/2013 05:20 PM, Michal Privoznik wrote:
> The virsh domfstrim command was not freeing allocated domain,
> leaving leaked references behind.
> ---
>  tools/virsh-domain.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 5ddcedc..5fbfeee 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -10058,6 +10058,8 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd)
>      ret = true;
>  
>  cleanup:
> +    if (dom)
> +        virDomainFree(dom);
>      return ret;
>  }
>  
> 

Alternatively, you could also get out of this with one line less:

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index d32218f..99f19a4 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10057,7 +10057,7 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd)
     unsigned int flags = 0;

     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
-        goto cleanup;
+        return false;

     if (vshCommandOptULongLong(cmd, "minimum", &minimum) < 0) {
         vshError(ctl, _("Unable to parse integer parameter minimum"));
@@ -10075,6 +10075,7 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd)
     ret = true;

 cleanup:
+    virDomainFree(dom);
     return ret;
 }
--

However, your approach works as well. ACK.

Martin ;-)


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