From 1dd26808779078e6ef2ca9a2ff384c2b99f3dac5 Mon Sep 17 00:00:00 2001 From: Bob Beck Date: Fri, 5 Mar 2004 00:31:06 +0000 Subject: Fix really dumb memory leak that would have long runnign large whitelist servers having their pf update process growing massive as it leaked huge tracks of whitelist. ok millert@ --- libexec/spamd/grey.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'libexec/spamd/grey.c') diff --git a/libexec/spamd/grey.c b/libexec/spamd/grey.c index 5aeeb01b1d3..85987b8eeb3 100644 --- a/libexec/spamd/grey.c +++ b/libexec/spamd/grey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grey.c,v 1.7 2004/03/01 17:03:10 otto Exp $ */ +/* $OpenBSD: grey.c,v 1.8 2004/03/05 00:31:05 beck Exp $ */ /* * Copyright (c) 2004 Bob Beck. All rights reserved. @@ -106,16 +106,26 @@ configure_pf(char **addrs, int count) return(-1); } for (i = 0; i < count; i++) - if (addrs[i] != NULL) { + if (addrs[i] != NULL) fprintf(pf, "%s/32\n", addrs[i]); - free(addrs[i]); - addrs[i] = NULL; - } fclose(pf); waitpid(pid, NULL, 0); return(0); } +void +freewhiteaddr(void) +{ + int i; + + if (whitelist != NULL) + for (i = 0; i < whitecount; i++) { + free(whitelist[i]); + whitelist[i] = NULL; + } + whitecount = 0; +} + /* validate, then add to list of addrs to whitelist */ int addwhiteaddr(char *addr) @@ -233,11 +243,13 @@ greyscan(char *dbname) db->sync(db, 0); db->close(db); db = NULL; + freewhiteaddr(); return(0); bad: db->sync(db, 0); db->close(db); db = NULL; + freewhiteaddr(); return(-1); } -- cgit v1.2.3