[syslog-ng] Memory leak when handling SIGHUP

Balazs Scheidler bazsi at balabit.hu
Thu Jul 26 12:49:38 CEST 2007


On Fri, 2007-07-13 at 09:51 +1200, anthony lineham wrote:
> Hi Bazsi,
> 
> I've finally found the memory leak I noticed when syslog-ng handles a
> SIGHUP. It turned out that
> there were 3 leaks. They are not very big so perhaps not significant
> for most users but in my system
> there is limited memory and frequent use of SIGHUP.
> 
> I've attached a patch that I believe resolves the leaks. Valgrind seems
> to like it. 
> However please let me know if there are any problems with it. This is
> the first time I've really gotten into
> the code so I'm sure I may have overlooked something.
> 
> Please note that my original fix was made and tested on 2.0.0+20061212,
> but the attached patch is for 2.0.4.
> I didn't notice any differences that would seem to impact the fix, but
> I may have missed something.
> 
> Here's a description of the changes:
> cfg-grammar.y
> cfg-grammar.c
> - The template reference counter gets incremented in the template
> lookup
> function, so remove the second increment here. Otherwise the counter
> never gets back to 0 and the template won't be able to be deleted.

This was correct, I applied the fix unchanged.

> 
> affile.c
> affile_dd_deinit:
> + Unreference the writer after de-initing it. The unreference will
> cause
> the writer to be deleted, which causes it to unreference this
> destination
> driver (a circular reference). When the call to affile_dd_free is made
> via cfg_free() the ref counter will be 1, allowing a final decrement
> and hence the removal of the destination diver. Previously the counter
> was
> 2 due to the writer reference, which prevented the destination driver
> from
> being removed.

I did not apply this one yet. I started working on an issue reported by
Evan Rempel in the same area, and I want to finish that first. I will
try to cover this leak in that work too.

> 
> templates.c
> + When freeing a template also deallocate the memory used by a
> compiled
> template.

I changed this slightly, but also applied.

Thanks for the thourough analysis of the leaks, and the fixes.

I've pushed the git archive to my public repository, so it should be
available there, or in tomorrow's snapshot.

-- 
Bazsi



More information about the syslog-ng mailing list