Thanks for the tip Matthias.<div><br></div><div>I found some time to check the code and came up with this patch:</div><div><br></div><div>diff --git a/src/libvirt-php.c b/src/libvirt-php.c</div><div>index 2045c59..8e215f4 100644</div><div>--- a/src/libvirt-php.c</div><div>+++ b/src/libvirt-php.c</div><div>@@ -9105,17 +9105,21 @@ PHP_FUNCTION(libvirt_list_active_domains)</div><div>     int count=-1;</div><div>     int expectedcount=-1;</div><div>     int *ids;</div><div>-    int i;</div><div>-    virDomainPtr domain = NULL;</div><div>     const char *name;</div><div>+    int i, rv;</div><div>+    virDomainPtr domain=NULL;</div><div> </div><div>     GET_CONNECTION_FROM_ARGS("r",&zconn);</div><div> </div><div>     if ((expectedcount=virConnectNumOfDomains (conn->conn)) < 0)</div><div>         RETURN_FALSE;</div><div> </div><div>+    DPRINTF("%s: Found %d domains\n", PHPFUNC, expectedcount);</div><div>+</div><div>     ids=(int *)emalloc(sizeof(int)*expectedcount);</div><div>     count=virConnectListDomains (conn->conn,ids,expectedcount);</div><div>+    DPRINTF("%s: virConnectListDomains returned %d domains\n", PHPFUNC, count);</div><div>+</div><div>     if ((count != expectedcount) || (count<0))</div><div>     {</div><div>         efree (ids);</div><div>@@ -9126,21 +9130,26 @@ PHP_FUNCTION(libvirt_list_active_domains)</div><div>     for (i=0;i<count;i++)</div><div>     {</div><div>         domain=virDomainLookupByID(conn->conn,ids[i]);</div><div>+        resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, domain, 1 TSRMLS_CC);</div><div>         if (domain!=NULL)</div><div>         {</div><div>             name=virDomainGetName(domain);</div><div>-</div><div>-            if (virDomainFree (domain))</div><div>-                resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, domain, 0 TSRMLS_CC);</div><div>-</div><div>-            if (name==NULL)</div><div>-            {</div><div>-                efree (ids);</div><div>-                RETURN_FALSE;</div><div>+            if (name != NULL) {</div><div>+                DPRINTF("%s: Found running domain %s with ID = %d\n", PHPFUNC, name, ids[i]);</div><div>+                VIRT_ADD_NEXT_INDEX_STRING(return_value, name);</div><div>             }</div><div>-</div><div>-            VIRT_ADD_NEXT_INDEX_STRING(return_value, name);</div><div>+            else</div><div>+                DPRINTF("%s: Cannot get ID for running domain %d\n", PHPFUNC, ids[i]);</div><div>         }</div><div>+        rv = virDomainFree (domain);</div><div>+        if (rv != 0) {</div><div>+            php_error_docref(NULL TSRMLS_CC, E_WARNING,"virDomainFree failed with %i on list_domain: %s",</div><div>+                             rv, LIBVIRT_G (last_error));</div><div>+        }</div><div>+        else {</div><div>+            resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, domain, 0 TSRMLS_CC);</div><div>+        }</div><div>+        domain = NULL;</div><div>     }</div><div>     efree(ids);</div><div> }</div><div><br></div><div><br></div><div>Basically I took the code from libvirt_list_domains and fit it in.</div><div>I'm almost sure it's not the most elegant and clean solution but it works fine in my tests.</div><div>Hopefully a fix will be included in the next libvirt-php release.</div><div><br></div><div>Thanks.</div><div><br></div><div>Fer</div><div><br>On mié, sep 7, 2016 at 3:58 , Matthias Bolte <matthias.bolte@googlemail.com> wrote:<br>
<blockquote type="cite"><div class="plaintext" style="white-space: pre-wrap;">2016-09-07 14:20 GMT+02:00 Fernando Casas Schössow <<a href="mailto:casasfernando@hotmail.com">casasfernando@hotmail.com</a>>:
<blockquote> Hi all,

 I'm using libvirt-php to manage a Hyper-V 2012 R2 host.
 When trying to retrieve the active VMs using the function
 libvirt_list_active_domains() I get an array with the correct amount of
 items but with garbage instead of the domain names:

 Array ( [0] => P’*µ [1] => +µ [2] => `„*µ [3] => °Ø*µ [4] => Ð„*µ [5] =>
 `†*µ [6] => [7] => `†*µ [8] => [9] => p +µ [10] => p"+µ [11] => P#+µ [12] =>
 ß*µ )

 On the other hand libvirt_list_inactive_domains() and libvirt_list_domains()
 work as expected returning the right amount of items and the domain names
 correctly:

 libvirt_list_inactive_domains() output:

 Array ( [0] => DCHOMELAB01 [1] => VMFCSW7 [2] => REMOTEAPP01 [3] => MPSSD01
 [4] => CS16SVR )
</blockquote>
The problem is here

<a href="http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=src/libvirt-php.c;h=2045c59644075c00a22695d7b8534ff593120f14;hb=HEAD#l9131">http://libvirt.org/git/?p=libvirt-php.git;a=blob;f=src/libvirt-php.c;h=2045c59644075c00a22695d7b8534ff593120f14;hb=HEAD#l9131</a>

libvirt_list_active_domains gets the domain name using
virDomainGetName, then frees the domain object using virDomainFree
(this also frees the domain name) and afterwards tries to use the
already freed domain name.

libvirt_list_active_domains needs to add the domian name to the result
list and then free the domain. For example, libvirt_list_domains does
it in the correct order.

<div>-- 
</div>Matthias Bolte
<a href="http://photron.blogspot.com">http://photron.blogspot.com</a>
</div></blockquote></div>