If you malloc/calloc/realloc without a free you will leak memory.

Do you have some reason to believe that another module might prevent your
module's calls to free() from being run?  What do you have in mind
specifically?

You can also mimic realloc by just allocating more memory from the pool and
calling memcpy.  The old memory will leak into the pool but be resolved on
pool cleanup.


I can tell you that malloc/free works fine inside an Apache module:
mod_pagespeed is written in C++ and uses new/delete extensively with the
default underlying malloc/free implementation.  We load-test extensively and
watch for leaks carefully via top, in addition to running valgrind on small
system tests.  This methodology is sound.  I'm not sure why you think your
calls to free would not happen.

-Josh

On Wed, Sep 14, 2011 at 8:01 AM, Christoph Gröver <gro...@sitepark.com>wrote:

>
> Hello list,
>
> In a module I have to allocate and reallocate a chunk of memory.
> Because (AFAIK) Apache or its libraries do not support reallocation
> I use the standard functions malloc/realloc (and free), of course.
>
> But what if there's a problem in another module?
>
> Is it possible that due to some errors somewhere else the
> malloc/realloc of my modules are run (and therefor memory is allocated)
> but the corresponding free is not called, because the thread/process
> had a strange ending.
>
> So would this result in a memory leak? (if this happens often!)
>
> Hope you can enlight me on this topic.
>
> Bye,
>
> --
> Christoph Gröver, gro...@sitepark.com
>
>

Reply via email to