[libvirt-users] undefining and redefining a Domain

Roberto Attias (rattias) rattias at cisco.com
Fri Oct 1 16:14:02 UTC 2010


Yes, I was calling free() instead of virDomainFree. Thanks!

-----Original Message-----
From: Matthias Bolte [mailto:matthias.bolte at googlemail.com] 
Sent: Friday, October 01, 2010 9:11 AM
To: Roberto Attias (rattias)
Cc: libvirt-users at redhat.com
Subject: Re: [libvirt-users] undefining and redefining a Domain

2010/10/1 Roberto Attias (rattias) <rattias at cisco.com>:
> <resending as I don’t think I was in the mailing list yet when I sent first
> time… apologies if you receive this twice>
>
>
>
> Hello,
>
> I’m facing some strange behavior, and I hope you can provide a
> clarification.
>
> Consider the following code:
>
>
>
>      virDomainPtr dom = virDomainLookupByName(virt, domain_name);
>
>      if (dom) {
>
>            printf("domain already defined...\n");
>
>            if (virDomainUndefine(dom))
>
>                 printf("...unable to undefine!!!\n");
>
>            else {
>
>                 printf("...undefined.");
>
>                 free(dom);
>
>            }
>
>      }

You're leaking a virDomainPtr here. Call virDomainFree(dom) before
overwriting the pointer with the result from virDomainDefineXML.

I think the leaked virDomainPtr causes the trouble you describe. So
fixing the leak will probably also fix the problem you see in the
second run.

>      dom = virDomainDefineXML(virt, SOME_XML);
>

Matthias




More information about the libvirt-users mailing list