[libvirt] libvirt-php and xpath function from libxml2

Hi! I'm test under high load some libvirt-php xpath based function and big memory leak under each function call. I'm try to patch libvirt-php to free some values via xmlFree , but this is not solve leaks. Do we realy need this function? As i see when i'm use plain libvirt function and use returned xml with internal php functions that works with xml and xpath, i'm not get memory leaks. So does we really need it? -- Vasiliy Tolstov, e-mail: v.tolstov@selfip.ru

On 14.10.2015 10:01, Vasiliy Tolstov wrote:
Hi! I'm test under high load some libvirt-php xpath based function and big memory leak under each function call. I'm try to patch libvirt-php to free some values via xmlFree , but this is not solve leaks. Do we realy need this function? As i see when i'm use plain libvirt function and use returned xml with internal php functions that works with xml and xpath, i'm not get memory leaks.
So does we really need it?
Hey, 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. Michal

2015-10-14 11:39 GMT+03:00 Michal Privoznik <mprivozn@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. 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. -- Vasiliy Tolstov, e-mail: v.tolstov@selfip.ru

On 14.10.2015 11:29, Vasiliy Tolstov wrote:
2015-10-14 11:39 GMT+03:00 Michal Privoznik <mprivozn@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? Michal
participants (2)
-
Michal Privoznik
-
Vasiliy Tolstov