2010/10/1 Roberto Attias (rattias) <rattias@xxxxxxxxx>: > <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