[libvirt] [PATCH 19/20] xend: Remove 4kb stack allocation

Matthias Bolte matthias.bolte at googlemail.com
Sun Apr 3 09:21:32 UTC 2011


---
 src/xen/xend_internal.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 8859373..8b07a8a 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -279,11 +279,17 @@ istartswith(const char *haystack, const char *needle)
 static int ATTRIBUTE_NONNULL (2)
 xend_req(int fd, char **content)
 {
-    char buffer[4096];
+    char *buffer;
+    size_t buffer_size = 4096;
     int content_length = 0;
     int retcode = 0;
 
-    while (sreads(fd, buffer, sizeof(buffer)) > 0) {
+    if (VIR_ALLOC_N(buffer, buffer_size) < 0) {
+        virReportOOMError();
+        return -1;
+    }
+
+    while (sreads(fd, buffer, buffer_size) > 0) {
         if (STREQ(buffer, "\r\n"))
             break;
 
@@ -293,6 +299,8 @@ xend_req(int fd, char **content)
             retcode = atoi(buffer + 9);
     }
 
+    VIR_FREE(buffer);
+
     if (content_length > 0) {
         ssize_t ret;
 
-- 
1.7.0.4




More information about the libvir-list mailing list