[libvirt] libvirt-php and xpath function from libxml2

Michal Privoznik mprivozn at redhat.com
Wed Oct 14 11:28:12 UTC 2015

On 14.10.2015 11:29, Vasiliy Tolstov wrote:
> 2015-10-14 11:39 GMT+03:00 Michal Privoznik <mprivozn at redhat.com>:
>> are you trying the latest git HEAD? Because I resolved some mem leaks there.
>> Maybe the problem is, the value passed to caller is not unset()
>> (something like free() in php), or we are setting wrong reference
>> counters somewhere.
> I'm try master head, also i'm add in get_string_from_xpath string
> xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1)
> allocates char * that needs to be freed, but it only checked with
> NULL, and later value is duplicated (allocating another memory block
> in add_assoc_string_ex ) . i'm rearrange some code paths, but leaks
> not solved.

Ah, so this is the problem. You need to xmlFree() the xpath result, once
strduped(). Alternatively, don't strdup and pass ownership of the string
to libvirt-php. BTW: what function are you looking at?

> I have simple php script, that use functions that internally use
> get_string_from_xpath and after 100-200 executions i have is about
> 1.5Gb memory wasted by script. May be this is internally php problem,
> i'm try unset, run gc but this is not helps.
> I'm remove all functions that use get_string_from_xpath and get xml
> via libvirt and after that all leaks dissapeared.
> So i voted to remove unneded functions and provide only libvirt
> bindings. All other logic can be created with provided binding. Like
> golang libvirt binding.

Yes, we should remove unneeded functions. Mind proposing a patch?


More information about the libvir-list mailing list