[libvirt] [PATCH] Cleanup virBuffer usage in qemdBuildCommandLine

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

 



Dan Berrangé pointed out that using virBufferError() is preferred to checking
virBufferContentAndReset() for NULL return. Also, this allows ADD_ARG_LIT to be
replaced with ADD_ARG, skipping an intermediate variable.

* src/qemu_qemu_conf.c: Cleanup usage of virBuffer in qemudBuildCommandLine
---
 src/qemu/qemu_conf.c |   15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index f010f4a..4a278e3 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -2182,7 +2182,6 @@ int qemudBuildCommandLine(virConnectPtr conn,
 
     for (i = 0 ; i < def->nchannels ; i++) {
         virBuffer buf = VIR_BUFFER_INITIALIZER;
-        const char *argStr;
         char id[16];
 
         virDomainChrDefPtr channel = def->channels[i];
@@ -2199,24 +2198,18 @@ int qemudBuildCommandLine(virConnectPtr conn,
             }
 
             qemudBuildCommandLineChrDevChardevStr(channel, id, &buf);
-            argStr = virBufferContentAndReset(&buf);
-            if (argStr == NULL)
+            if (virBufferError(&buf))
                 goto error;
 
             ADD_ARG_LIT("-chardev");
-            ADD_ARG_LIT(argStr);
-
-            VIR_FREE(argStr);
+            ADD_ARG(virBufferContentAndReset(&buf));
 
             qemudBuildCommandLineChrDevTargetStr(channel, id, &buf);
-            argStr = virBufferContentAndReset(&buf);
-            if (argStr == NULL)
+            if (virBufferError(&buf))
                 goto error;
 
             ADD_ARG_LIT("-net");
-            ADD_ARG_LIT(argStr);
-
-            VIR_FREE(argStr);
+            ADD_ARG(virBufferContentAndReset(&buf));
         }
     }
 
-- 
1.6.2.5

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