[PATCH] qemu: Avoid needless copies of static strings

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

 



Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index bf6430d..f88520f 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3931,7 +3931,8 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
     time_t now = time(NULL);
-    char expire_time [64];
+    const char *expire;
+    char *validTo = NULL;
     const char *connected = NULL;
     const char *password;
     int ret = -1;
@@ -3962,19 +3963,18 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
     if (ret != 0)
         goto end_job;
 
-    if (password[0] == '\0') {
-        snprintf(expire_time, sizeof(expire_time), "now");
+    if (password[0] == '\0' ||
+        (auth->expires && auth->validTo <= now)) {
+        expire = "now";
     } else if (auth->expires) {
-        time_t lifetime = auth->validTo - now;
-        if (lifetime <= 0)
-            snprintf(expire_time, sizeof(expire_time), "now");
-        else
-            snprintf(expire_time, sizeof(expire_time), "%lu", (long unsigned)auth->validTo);
+        if (virAsprintf(&validTo, "%lu", (unsigned long) auth->validTo) < 0)
+            goto end_job;
+        expire = validTo;
     } else {
-        snprintf(expire_time, sizeof(expire_time), "never");
+        expire = "never";
     }
 
-    ret = qemuMonitorExpirePassword(priv->mon, type, expire_time);
+    ret = qemuMonitorExpirePassword(priv->mon, type, expire);
 
     if (ret == -2) {
         /* XXX we could fake this with a timer */
@@ -3991,6 +3991,7 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         ret = -1;
  cleanup:
+    VIR_FREE(validTo);
     virObjectUnref(cfg);
     return ret;
 }
-- 
2.9.0

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