[PATCH v2 01/17] virfdstream: Use g_autofree in virFDStreamThreadDoRead()

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

 



The buffer that allocated in the virFDStreamThreadDoRead() can be
automatically freed, or if saved into the message structure it
can be stolen.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/virfdstream.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c
index 1c32be47a9..e29c95690b 100644
--- a/src/util/virfdstream.c
+++ b/src/util/virfdstream.c
@@ -431,7 +431,7 @@ virFDStreamThreadDoRead(virFDStreamDataPtr fdst,
     virFDStreamMsgPtr msg = NULL;
     int inData = 0;
     long long sectionLen = 0;
-    char *buf = NULL;
+    g_autofree char *buf = NULL;
     ssize_t got;
 
     if (sparse && *dataLen == 0) {
@@ -483,9 +483,8 @@ virFDStreamThreadDoRead(virFDStreamDataPtr fdst,
         }
 
         msg->type = VIR_FDSTREAM_MSG_TYPE_DATA;
-        msg->stream.data.buf = buf;
+        msg->stream.data.buf = g_steal_pointer(&buf);
         msg->stream.data.len = got;
-        buf = NULL;
         if (sparse)
             *dataLen -= got;
     }
@@ -496,7 +495,6 @@ virFDStreamThreadDoRead(virFDStreamDataPtr fdst,
     return got;
 
  error:
-    VIR_FREE(buf);
     virFDStreamMsgFree(msg);
     return -1;
 }
-- 
2.26.2




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

  Powered by Linux