httpd-apreq-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From is...@apache.org
Subject svn commit: r542899 - /httpd/apreq/branches/1.x/c/apache_multipart_buffer.c
Date Wed, 30 May 2007 17:54:10 GMT
Author: issac
Date: Wed May 30 10:54:09 2007
New Revision: 542899

URL: http://svn.apache.org/viewvc?view=rev&rev=542899
Log:
Use a non-quadratic memory allocation algorithm for multipart requests (joes) - see http://mail-archives.apache.org/mod_mbox/httpd-apreq-dev/200705.mbox/%3c876474e28s.fsf_-_@gemini.sunstarsys.com%3e

Modified:
    httpd/apreq/branches/1.x/c/apache_multipart_buffer.c

Modified: httpd/apreq/branches/1.x/c/apache_multipart_buffer.c
URL: http://svn.apache.org/viewvc/httpd/apreq/branches/1.x/c/apache_multipart_buffer.c?view=diff&rev=542899&r1=542898&r2=542899
==============================================================================
--- httpd/apreq/branches/1.x/c/apache_multipart_buffer.c (original)
+++ httpd/apreq/branches/1.x/c/apache_multipart_buffer.c Wed May 30 10:54:09 2007
@@ -273,16 +273,24 @@
     return len;
 }
 
-/*
-  XXX: this is horrible memory-usage-wise, but we only expect
-  to do this on small pieces of form data.
-*/
 char *multipart_buffer_read_body(multipart_buffer *self)
 {
     char buf[FILLUNIT], *out = "";
+    size_t nalloc = 1, cur_len = 0;
 
-    while(multipart_buffer_read(self, buf, sizeof(buf)))
-	out = ap_pstrcat(self->r->pool, out, buf, NULL);
+    while(multipart_buffer_read(self, buf, sizeof(buf))) {
+        size_t len = strlen(buf);
+        if (len + cur_len + 1 > nalloc) {
+            char *tmp;
+            nalloc = 2 * (nalloc + len + 1);
+            tmp = ap_palloc(self->r->pool, nalloc);
+            strcpy(tmp, out);
+            out = tmp;
+        }
+
+        strcpy(out + cur_len, buf);
+        cur_len += len;
+    }
 
 #ifdef DEBUG
     ap_log_rerror(MPB_ERROR, "multipart_buffer_read_body: '%s'", out);



Mime
View raw message