[PATCHv4 12/17] rpc: use VIR_(APPEND|DELETE)_ELEMENT for netserver client lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The pointer in client continues to be used after the APPEND is done,
so we must use the _COPY variant of the append macro.
---
 src/rpc/virnetserver.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index 6a5a53a..6d3ba70 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -277,11 +277,10 @@ static int virNetServerAddClient(virNetServerPtr srv,
     if (virNetServerClientInit(client) < 0)
         goto error;
 
-    if (VIR_EXPAND_N(srv->clients, srv->nclients, 1) < 0) {
+    if (VIR_APPEND_ELEMENT_COPY(srv->clients, srv->nclients, client) < 0) {
         virReportOOMError();
         goto error;
     }
-    srv->clients[srv->nclients-1] = client;
     virObjectRef(client);
 
     virNetServerClientSetDispatcher(client,
@@ -1134,16 +1133,7 @@ void virNetServerRun(virNetServerPtr srv)
                 virNetServerClientClose(srv->clients[i]);
             if (virNetServerClientIsClosed(srv->clients[i])) {
                 virObjectUnref(srv->clients[i]);
-                if (srv->nclients > 1) {
-                    memmove(srv->clients + i,
-                            srv->clients + i + 1,
-                            sizeof(*srv->clients) * (srv->nclients - (i + 1)));
-                    VIR_SHRINK_N(srv->clients, srv->nclients, 1);
-                } else {
-                    VIR_FREE(srv->clients);
-                    srv->nclients = 0;
-                }
-
+                VIR_DELETE_ELEMENT(srv->clients, i, srv->nclients);
                 goto reprocess;
             }
         }
-- 
1.7.11.7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]