Memory leak in Clayton O'neill's HIScache patches
Subject: Memory leak in Clayton O'neill's HIScache patches
From: gpalmer@SPAM.webspan.net (Gary Palmer)
Date: 1997/06/30
Message-Id: <5p9h1p$mom@news.webspan.net>
Newsgroups: news.software.nntp
For those that are using the history cache patches, I have noticed a
rather subtle memory leak, but a nasty one nonetheless (it can ammount
to several MB's a day)
Cause:
HIScache malloc's memory (using strdup) for storage of the
Message-ID's for comparison to stop hash overlapping from rejecting
articles not already received. However, when the history file is
reloaded (e.g. by expire during news.daily), the history file is
closed (using HISclose) and re-opened using the HISsetup
function. Clayton's patch memset's the HIScache array back to 0 in the
HISsetup function. This loses all the pointers to the malloc'd areas
of memory for ever (unless you have a *VERY* smart malloc
implimentation).
Given an `average' Message-ID length of 80 characters (or is it 70? I
forget), you could lose up to 4.5Mb of core memory per reload if you
run with the default cache size.
Solution:
You need to do something like
/*
** Set up the history files.
*/
void
HISsetup()
{
static int HIScachezeroed = FALSE;
( .... )
if (HIScachezeroed == FALSE) {
memset((void *)&HIScache, '\0', sizeof(HIScache));
HIScachezeroed = TRUE;
}
}
This should stop the leakage. I have informed Clayton about this, but
I'm not sure if he is going to re-roll his patch as I believe his
sources have diverged too far from the baseline to generate a clean
diff. If there is interest, I could re-roll it with another local
change (it stops multiple transfers of articles for groups we don't
want)
Gary
In order to prevent duplicate entries which will corrupt the history file, it is necessary to purge the cache when the history file is reloaded. This is especially important anytime inn is paused and the history file is changed externally. Use this patch instead: http://www.mibsoftware.com/userkt/inn/patches/hiscacheleak.diff
You can find a summary and links related to this topic
as part of the Mib Software Usenet RKT.