apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Fallin <ch...@cfallin.org>
Subject Problem avoiding memory leak with thread creation
Date Fri, 05 Sep 2003 04:27:15 GMT
Hello everyone,

I'm developing a small server application using APR. As part of the 
design each new session spawns a thread. The application will be 
long-running and so must not leak memory.

In order to prevent leaks each thread gets its own subpool, which it 
frees on exit. However, I see in apr_thread_create (at 
threadproc/unix/thread.c:160) that a subpool is allocated from the pool 
passed to the function. This pool is the one that is destroyed in 
apr_thread_exit at line 192. Thus, the pool passed in to 
apr_thread_create is never freed unless done manually after 
apr_thread_exit destroys the child pool, which is hard because it exits 
the thread.

The fact that leads me to believe it may be a bug is that on line 151 
the 'pool' member is assigned to the pool that's passed in. Or maybe 
it's a design decision - I don't know. Nevertheless, what is the 
recommended way to avoid a memory leak in this situation?

Thanks in advance
-- 
Chris Fallin
Email: chris@cfallin.org
AIM  : ProgrammerNerd1
URL  : http://www.cfallin.org/


Mime
View raw message