Graham Dumpleton commented on MODPYTHON-184:

The cause of this seems to result from the following.

1. The apache.make_table attribute is actually an alias for the type object for 

2. Calling apache.make_table() invokes the table_new() method of the "mp_table" 

3. The table_new() method in turn calls table_alloc() of the "mp_table" type.

4. In table_alloc() it calls MpTable_New() which creates a whole and complete 
"mp_table" object instance.

5. After table_alloc() returns to table_new(), the code following duplicates 
the creation process again creating a new "mp_table" object instance which 
replaces the first one created. The first one created is now no longer 

The problematic code is:

    self = type->tp_alloc(type, 0);
    if (self != NULL) {
        apr_pool_t *p;
        tableobject *t = (tableobject *)self;
        apr_pool_create_ex(&p, NULL, NULL, NULL);
        t->pool = p;
        t->table = apr_table_make(p, 2);

I think it may be a simple case of the 'if' clause being the wrong way around. 
Ie., should be:

    self = type->tp_alloc(type, 0);
    if (!self) {
        apr_pool_t *p;
        tableobject *t = (tableobject *)self;
        apr_pool_create_ex(&p, NULL, NULL, NULL);
        t->pool = p;
        t->table = apr_table_make(p, 2);

In fact, since table_alloc() always returns a non NULL value, it could just be:

    self = type->tp_alloc(type, 0);

The issue now is what is the difference between tp_alloc and tp_new hooks in a 
Python type object object. I haven't used these in a while, so will have to 
research some more as to what is meant to occur in each.

> Memory leak apache.table()
> --------------------------
>                 Key: MODPYTHON-184
>                 URL: http://issues.apache.org/jira/browse/MODPYTHON-184
>             Project: mod_python
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.3, 3.2.10
>            Reporter: Jim Gallacher
>         Assigned To: Jim Gallacher
>             Fix For: 3.3
> There is a memory leak in apache.table().
> from mod_python import apache
> def handler(req):
>     req.content_type = 'text/plain'
>     t = apache.make_table()
>     req.write('ok table:')
>     return apache.OK
> Using mpm-worker with StartServers 2, and 20000 requests results in memory 
> consumption going from 1.2% to 9.3% per process. (ie approx 8k per request)
> This will have an impact on FieldStorage which makes use of 
> apache.make_table(), which is the deprecated name for apache.table()

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: 
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to