Add support for freeing a remap file datastructure, so we avoid a

memory leak.
This commit is contained in:
hpa 2001-08-10 18:07:46 +00:00
parent 519eb0ba91
commit e3570e4d31
3 changed files with 26 additions and 3 deletions

View file

@ -239,6 +239,26 @@ struct rule *parserulefile(FILE *f)
return first_rule; return first_rule;
} }
/* Destroy a rule file data structure */
void freerules(struct rule *r)
{
struct rule *next;
while ( r ) {
next = r->next;
regfree(&r->rx);
/* "" patterns aren't allocated by malloc() */
if ( r->pattern && *r->pattern )
free(r->pattern);
free(r);
r = next;
}
}
/* Execute a rule set on a string; returns a malloc'd new string. */ /* Execute a rule set on a string; returns a malloc'd new string. */
char *rewrite_string(const char *input, const struct rule *rules, int is_put) char *rewrite_string(const char *input, const struct rule *rules, int is_put)
{ {

View file

@ -30,6 +30,9 @@ struct rule;
/* Read a rule file */ /* Read a rule file */
struct rule *parserulefile(FILE *); struct rule *parserulefile(FILE *);
/* Destroy a rule file data structure */
void freerules(struct rule *);
/* Execute a rule set on a string; returns a malloc'd new string. */ /* Execute a rule set on a string; returns a malloc'd new string. */
char *rewrite_string(const char *, const struct rule *, int); char *rewrite_string(const char *, const struct rule *, int);

View file

@ -395,10 +395,10 @@ main(int argc, char **argv)
caught_sighup = 0; caught_sighup = 0;
if ( listen ) { if ( listen ) {
#ifdef HAVE_REGEX #ifdef HAVE_REGEX
/* This is unfortunately a memory leak. Hopefully if ( rewrite_file ) {
SIGHUPs aren't too common. */ freerules(rewrite_rules);
if ( rewrite_file )
rewrite_rules = read_remap_rules(rewrite_file); rewrite_rules = read_remap_rules(rewrite_file);
}
#endif #endif
} else { } else {
/* Return to inetd for respawn */ /* Return to inetd for respawn */