]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
phyp: Remove 16kb stack allocation
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sun, 3 Apr 2011 09:21:18 +0000 (11:21 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 5 Apr 2011 06:55:27 +0000 (08:55 +0200)
Allocate on the heap instead.

src/phyp/phyp_driver.c

index b17d90beff6e133fe95b69602ebb3f1276fc3ebd..ddbc10348ca0381025f24f79af5efef00f83cc71 100644 (file)
@@ -115,12 +115,18 @@ phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status,
     LIBSSH2_CHANNEL *channel;
     ConnectionData *connection_data = conn->networkPrivateData;
     virBuffer tex_ret = VIR_BUFFER_INITIALIZER;
-    char buffer[0x4000] = { 0 };
+    char *buffer = NULL;
+    size_t buffer_size = 16384;
     int exitcode;
     int bytecount = 0;
     int sock = connection_data->sock;
     int rc = 0;
 
+    if (VIR_ALLOC_N(buffer, buffer_size) < 0) {
+        virReportOOMError();
+        return NULL;
+    }
+
     /* Exec non-blocking on the remove host */
     while ((channel = libssh2_channel_open_session(session)) == NULL &&
            libssh2_session_last_error(session, NULL, NULL, 0) ==
@@ -144,7 +150,7 @@ phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status,
     for (;;) {
         /* loop until we block */
         do {
-            rc = libssh2_channel_read(channel, buffer, sizeof(buffer));
+            rc = libssh2_channel_read(channel, buffer, buffer_size);
             if (rc > 0) {
                 bytecount += rc;
                 virBufferVSprintf(&tex_ret, "%s", buffer);
@@ -179,9 +185,12 @@ phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status,
   err:
     (*exit_status) = SSH_CMD_ERR;
     virBufferFreeAndReset(&tex_ret);
+    VIR_FREE(buffer);
     return NULL;
 
   exit:
+    VIR_FREE(buffer);
+
     if (virBufferError(&tex_ret)) {
         virBufferFreeAndReset(&tex_ret);
         virReportOOMError();