[PATCH 2/4] rpc: Add virNetMessageClearPayload

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

 



Handles freeing the buffer and fds, but not the message details.
Use it to drop some duplicate code.
---
 src/rpc/virnetmessage.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c
index 5c57128..3df502a 100644
--- a/src/rpc/virnetmessage.c
+++ b/src/rpc/virnetmessage.c
@@ -49,17 +49,25 @@ virNetMessagePtr virNetMessageNew(bool tracked)
 }
 
 
-void virNetMessageClear(virNetMessagePtr msg)
+static void
+virNetMessageClearPayload(virNetMessagePtr msg)
 {
-    bool tracked = msg->tracked;
     size_t i;
 
-    VIR_DEBUG("msg=%p nfds=%zu", msg, msg->nfds);
-
     for (i = 0; i < msg->nfds; i++)
         VIR_FORCE_CLOSE(msg->fds[i]);
     VIR_FREE(msg->fds);
     VIR_FREE(msg->buffer);
+}
+
+
+void virNetMessageClear(virNetMessagePtr msg)
+{
+    bool tracked = msg->tracked;
+
+    VIR_DEBUG("msg=%p nfds=%zu", msg, msg->nfds);
+
+    virNetMessageClearPayload(msg);
     memset(msg, 0, sizeof(*msg));
     msg->tracked = tracked;
 }
@@ -67,7 +75,6 @@ void virNetMessageClear(virNetMessagePtr msg)
 
 void virNetMessageFree(virNetMessagePtr msg)
 {
-    size_t i;
     if (!msg)
         return;
 
@@ -76,10 +83,7 @@ void virNetMessageFree(virNetMessagePtr msg)
     if (msg->cb)
         msg->cb(msg, msg->opaque);
 
-    for (i = 0; i < msg->nfds; i++)
-        VIR_FORCE_CLOSE(msg->fds[i]);
-    VIR_FREE(msg->buffer);
-    VIR_FREE(msg->fds);
+    virNetMessageClearPayload(msg);
     VIR_FREE(msg);
 }
 
-- 
2.7.4

--
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]