From: Matthias Bolte Date: Sun, 3 Apr 2011 09:21:32 +0000 (+0200) Subject: xend: Remove 4kb stack allocation X-Git-Tag: v0.9.1~193 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9faf3d084c98b140aecc57b2b36d4cc8d1a839bb;p=thirdparty%2Flibvirt.git xend: Remove 4kb stack allocation --- diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 8859373fcc..8b07a8adff 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;