diff mbox

[2/4] rpc: Add virNetMessageClearPayload

Message ID 8946f4fef5ed3005b71f851047a77ac45d8d8935.1461796325.git.crobinso@redhat.com
State Accepted
Commit 220c4e85b36c0210c8915f0b4d0732e93383f5a3
Headers show

Commit Message

Cole Robinson April 27, 2016, 10:33 p.m. UTC
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(-)

-- 
2.7.4

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

Patch

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);
 }