Graham,

In http://svn.apache.org/viewvc/httpd/mod_python/trunk/src/ requestobject.c?view=markup&pathrev=431327, in req_readlines():


 /* is there anything left in the rbuff from previous reads? */
    if (self->rbuff_pos < self->rbuff_len) {

        /* if yes, process that first */
        while (self->rbuff_pos < self->rbuff_len) {

            buffer[copied++] = self->rbuff[self->rbuff_pos];
            if ((self->rbuff[self->rbuff_pos++] == '\n') ||
                (copied == len)) {

                /* our work is done */

                /* resize if necessary */
                if (copied < len)
                    if(_PyString_Resize(&result, copied))
                        return NULL;

return result; // RETURNING results without free(buffer)
            }
        }
    }

    /* 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;
    }

There is one of the memory leaks.

Putting the if statement "if (self->rbuff_pos >= self->rbuff_len && self->rbuff != NULL)" just before the "return result;" fix that one.

 /* is there anything left in the rbuff from previous reads? */
    if (self->rbuff_pos < self->rbuff_len) {

        /* if yes, process that first */
        while (self->rbuff_pos < self->rbuff_len) {

            buffer[copied++] = self->rbuff[self->rbuff_pos];
            if ((self->rbuff[self->rbuff_pos++] == '\n') ||
                (copied == len)) {

                /* our work is done */

                /* resize if necessary */
                if (copied < len)
                    if(_PyString_Resize(&result, copied))
                        return NULL;

if (self->rbuff_pos >= self->rbuff_len && self- >rbuff != NULL) {
                   free(self->rbuff);
                   self->rbuff = NULL;
                }
                return result;
            }
        }
    }





We also need to free the buffer in the "tp_dealloc" or some other function that is called when disposing the object.



/amn

On Aug 14, 2006, at 8:12 AM, Graham Dumpleton wrote:


On 14/08/2006, at 1:16 AM, Jim Gallacher wrote:
Only ask as I have a big patch related to MODPYTHON-63 that am wanting to commit back into the repository, but don't want to be doing it if it
is going
to make your search harder by introducing some new memory leaks. :-)

As long as you don't touch req_readline it shouldn't matter. I'm looking
at the memory difference between a simple handler (baseline) and the
specific test anyway, so if you introduce a leak elsewhere it will be
accounted for.

Okay, see how you go with what I just checked in. I did though forget to
cross reference to changes in commit message. Actual changes are:

  http://svn.apache.org/viewvc?view=rev&revision=431327

If it leaks badly let me know and I'll review my changes again.

Graham

Reply via email to