You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2003/08/04 16:54:46 UTC
cvs commit: httpd-python/src requestobject.c
grisha 2003/08/04 07:54:46
Modified: src requestobject.c
Log:
Patch to make sure that memory is freed in req.readline() to avoid problems
with uploading huge files.
Submitted by:Indrek J�rve
Revision Changes Path
1.50 +29 -2 httpd-python/src/requestobject.c
Index: requestobject.c
===================================================================
RCS file: /home/cvs/httpd-python/src/requestobject.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- requestobject.c 12 Jul 2003 03:44:53 -0000 1.49
+++ requestobject.c 4 Aug 2003 14:54:46 -0000 1.50
@@ -496,6 +496,12 @@
while ((self->rbuff_pos < self->rbuff_len) && (copied < len))
buffer[copied++] = self->rbuff[self->rbuff_pos++];
+ /* Free rbuff if we're done with it */
+ if (self->rbuff_pos >= self->rbuff_len && self->rbuff != NULL) {
+ free(self->rbuff);
+ self->rbuff = NULL;
+ }
+
if (copied == len)
return result; /* we're done! */
@@ -607,12 +613,21 @@
}
}
+ /* Free old rbuff as the old contents have been copied over and
+ we are about to allocate a new rbuff. Perhaps this could be reused
+ somehow? */
+ if (self->rbuff_pos >= self->rbuff_len && self->rbuff != NULL)
+ {
+ free(self->rbuff);
+ self->rbuff = NULL;
+ }
+
/* if got this far, the buffer should be empty, we need to read more */
/* create a read buffer */
self->rbuff_len = len > HUGE_STRING_LEN ? len : HUGE_STRING_LEN;
self->rbuff_pos = self->rbuff_len;
- self->rbuff = apr_palloc(self->request_rec->pool, self->rbuff_len);
+ self->rbuff = malloc(self->rbuff_len);
if (! self->rbuff)
return PyErr_NoMemory();
@@ -633,6 +648,11 @@
Py_END_ALLOW_THREADS
if (chunk_len == -1) {
+
+ /* Free rbuff since returning NULL here should end the request */
+ free(self->rbuff);
+ self->rbuff = NULL;
+
PyErr_SetObject(PyExc_IOError,
PyString_FromString("Client read error (Timeout?)"));
return NULL;
@@ -651,6 +671,13 @@
(copied == len))
/* our work is done */
break;
+ }
+
+ /* Free rbuff if we're done with it */
+ if (self->rbuff_pos >= self->rbuff_len && self->rbuff != NULL)
+ {
+ free(self->rbuff);
+ self->rbuff = NULL;
}
/* resize if necessary */