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

[libvirt] [PATCH 06/20] qemu: Use heap allocated memory to read the monitor greeting



Removing a 4kb stack allocation.

Reduce stack buffer for virStrerror to the common 1kb instead of 4kb.
---
 src/qemu/qemu_process.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 90fcea0..fc9fdae 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1012,7 +1012,8 @@ static int
 qemuProcessWaitForMonitor(struct qemud_driver* driver,
                           virDomainObjPtr vm, off_t pos)
 {
-    char buf[4096] = ""; /* Plenty of space to get startup greeting */
+    char *buf;
+    size_t buf_size = 4096; /* Plenty of space to get startup greeting */
     int logfd;
     int ret = -1;
     virHashTablePtr paths = NULL;
@@ -1020,7 +1021,12 @@ qemuProcessWaitForMonitor(struct qemud_driver* driver,
     if ((logfd = qemuProcessLogReadFD(driver->logDir, vm->def->name, pos)) < 0)
         return -1;
 
-    if (qemuProcessReadLogOutput(vm, logfd, buf, sizeof(buf),
+    if (VIR_ALLOC_N(buf, buf_size) < 0) {
+        virReportOOMError();
+        return -1;
+    }
+
+    if (qemuProcessReadLogOutput(vm, logfd, buf, buf_size,
                                  qemuProcessFindCharDevicePTYs,
                                  "console", 30) < 0)
         goto closelog;
@@ -1053,16 +1059,18 @@ cleanup:
     if (kill(vm->pid, 0) == -1 && errno == ESRCH) {
         /* VM is dead, any other error raised in the interim is probably
          * not as important as the qemu cmdline output */
-        qemuProcessReadLogFD(logfd, buf, sizeof(buf), strlen(buf));
+        qemuProcessReadLogFD(logfd, buf, buf_size, strlen(buf));
         qemuReportError(VIR_ERR_INTERNAL_ERROR,
                         _("process exited while connecting to monitor: %s"),
                         buf);
         ret = -1;
     }
 
+    VIR_FREE(buf);
+
 closelog:
     if (VIR_CLOSE(logfd) < 0) {
-        char ebuf[4096];
+        char ebuf[1024];
         VIR_WARN("Unable to close logfile: %s",
                  virStrerror(errno, ebuf, sizeof ebuf));
     }
-- 
1.7.0.4


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