[cvslog] (2005-05-31 03:35:18 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Mon May 30 21:35:19 CST 2005


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2005-05-31 03:35:18 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     lib/eggdrop/memutil.c lib/eggdrop/sockbuf.c
     modules/chanserv/chanserv.c modules/chanserv/chanserv.h
     modules/server/input.c

Log message:

* Fixed some memleaks I found with valgrind

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/memutil.c
diff -u eggdrop1.9/lib/eggdrop/memutil.c:1.20 eggdrop1.9/lib/eggdrop/memutil.c:1.21
--- eggdrop1.9/lib/eggdrop/memutil.c:1.20	Sun Oct 17 00:14:06 2004
+++ eggdrop1.9/lib/eggdrop/memutil.c	Mon May 30 22:35:07 2005
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: memutil.c,v 1.20 2004/10/17 05:14:06 stdarg Exp $";
+static const char rcsid[] = "$Id: memutil.c,v 1.21 2005/05/31 03:35:07 stdarg Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -85,5 +85,6 @@
 		if (!(n % 1024)) n = strlen(output);
 		*final_len = n;
 	}
+	if (output != buf && len - n > 256) output = realloc(output, n+20);
 	return(output);
 }
Index: eggdrop1.9/lib/eggdrop/sockbuf.c
diff -u eggdrop1.9/lib/eggdrop/sockbuf.c:1.17 eggdrop1.9/lib/eggdrop/sockbuf.c:1.18
--- eggdrop1.9/lib/eggdrop/sockbuf.c:1.17	Sun Oct 17 00:14:06 2004
+++ eggdrop1.9/lib/eggdrop/sockbuf.c	Mon May 30 22:35:08 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: sockbuf.c,v 1.17 2004/10/17 05:14:06 stdarg Exp $";
+static const char rcsid[] = "$Id: sockbuf.c,v 1.18 2005/05/31 03:35:08 stdarg Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -376,6 +376,7 @@
 	timer_get_now(&sockbufs[newidx].stats->connected_at);
 	sockbuf_set_sock(newidx, newsock, SOCKBUF_INBOUND);
 	sockbuf_on_newclient(idx, SOCKBUF_LEVEL_INTERNAL, newidx, peer_ip, peer_port);
+	free(peer_ip);
 }
 
 /* This is called when the POLLOUT condition is true for already-connected
@@ -614,8 +615,9 @@
 	/* Close the file descriptor. */
 	if (sbuf->sock >= 0) socket_close(sbuf->sock);
 
-	/* Free the peer ip. */
+	/* Free ip data. */
 	if (sbuf->peer_ip) free(sbuf->peer_ip);
+	if (sbuf->my_ip) free(sbuf->my_ip);
 
 	/* Free its output buffer. */
 	if (sbuf->data) free(sbuf->data);
Index: eggdrop1.9/modules/chanserv/chanserv.c
diff -u eggdrop1.9/modules/chanserv/chanserv.c:1.3 eggdrop1.9/modules/chanserv/chanserv.c:1.4
--- eggdrop1.9/modules/chanserv/chanserv.c:1.3	Sat May  7 23:40:12 2005
+++ eggdrop1.9/modules/chanserv/chanserv.c	Mon May 30 22:35:08 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: chanserv.c,v 1.3 2005/05/08 04:40:12 stdarg Exp $";
+static const char rcsid[] = "$Id: chanserv.c,v 1.4 2005/05/31 03:35:08 stdarg Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -28,6 +28,8 @@
 chanserv_config_t chanserv_config;
 egg_server_api_t *server = NULL;
 static chanserv_channel_stats_t global_chan;
+static int timer_id;
+static int chanserv_timer(void *client_data);
 
 /* This array is in the same sequence as the CHANSERV_STAT_* constants. */
 static const char *channel_config_names[] = {
@@ -81,12 +83,17 @@
 
 static int chanserv_init()
 {
+	egg_timeval_t howlong;
+
 	memset(&global_chan, 0, sizeof(global_chan));
 	BT_chanflood = bind_table_add("chanflood", 5, "ssiii", MATCH_MASK, BIND_STACKABLE);
 	BT_memflood = bind_table_add("memflood", 7, "ssssiii", MATCH_MASK, BIND_STACKABLE);
 	server = module_get_api("server", 1, 0);
 	bind_add_simple("chanset", NULL, "settings.chanserv.*", on_chanset);
 	events_init();
+	howlong.sec = CHANSERV_CLEANUP_TIMER;
+	howlong.usec = 0;
+	timer_id = timer_create_complex(&howlong, "chanserv stats cleanup", chanserv_timer, NULL, TIMER_REPEAT);
 	return(0);
 }
 
@@ -98,8 +105,9 @@
 	return(0);
 }
 
-int chanserv_refresh_channel_config(chanserv_channel_stats_t *chanstats)
+int chanserv_refresh_channel_config(void *client_data)
 {
+	chanserv_channel_stats_t *chanstats = client_data;
 	channel_t *chan = server->channel_lookup(chanstats->name);
 	int i, setting;
 
@@ -173,6 +181,7 @@
 	/* Add new member. */
 	chan->members = realloc(chan->members, sizeof(*chan->members) * (chan->nmembers+1));
 	chan->nmembers++;
+	memset(chan->members+i, 0, sizeof(*chan->members));
 	chan->members[i].who = ircmask_create(5, nick, uhost);
 	return(chan->members+i);
 }
@@ -240,6 +249,7 @@
 
 	/* Now update member stats. */
 	if (m) {
+		m->last_event = now;
 		/* Figure out the period and limit for this stat. */
 		period = global_chan.periods[stat];
 		if (period > 0) {
@@ -263,11 +273,8 @@
 		}
 		
 		switch (stat) {
-			case CHANSERV_STAT_JOIN:
-				m->join_time = now;
-				break;
 			case CHANSERV_STAT_LEAVE:
-				if (now - m->join_time < chanserv_config.cycle_time) {
+				if (now - m->last_event_time[CHANSERV_STAT_JOIN] < chanserv_config.cycle_time) {
 					chanserv_update_stats(CHANSERV_STAT_CYCLE, chan, nick, uhost);
 				}
 				break;
@@ -276,6 +283,38 @@
 	return(0);
 }
 
+/* Clean up old entries. */
+static int cleanup_old_members(chanserv_channel_stats_t *chan)
+{
+	chanserv_member_stats_t *m;
+	time_t now;
+	int i;
+
+	now = timer_get_now_sec(NULL);
+
+	for (i = 0; i < chan->nmembers; i++) {
+		m = chan->members+i;
+		if (now - m->last_event > CHANSERV_CLEANUP_TIME) {
+			free(m->who);
+			memmove(chan->members+i, chan->members+i+1, sizeof(*chan->members)*(chan->nmembers-i-1));
+			chan->nmembers--;
+			i--;
+		}
+	}
+	return(0);
+}
+
+static int chanserv_timer(void *client_data)
+{
+	chanserv_channel_stats_t *chan;
+
+	for (chan = chanstats_head; chan; chan = chan->next) {
+		cleanup_old_members(chan);
+	}
+	cleanup_old_members(&global_chan);
+	return(0);
+}
+
 static int chanserv_close(int why)
 {
 	void *config_root;
Index: eggdrop1.9/modules/chanserv/chanserv.h
diff -u eggdrop1.9/modules/chanserv/chanserv.h:1.2 eggdrop1.9/modules/chanserv/chanserv.h:1.3
--- eggdrop1.9/modules/chanserv/chanserv.h:1.2	Thu Mar  3 12:45:26 2005
+++ eggdrop1.9/modules/chanserv/chanserv.h	Mon May 30 22:35:08 2005
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id: chanserv.h,v 1.2 2005/03/03 18:45:26 stdarg Exp $
+ * $Id: chanserv.h,v 1.3 2005/05/31 03:35:08 stdarg Exp $
  */
 
 #ifndef _EGG_MOD_CHANSERV_CHANSERV_H_
@@ -32,6 +32,9 @@
 
 #include "events.h"
 
+#define CHANSERV_CLEANUP_TIME	120
+#define CHANSERV_CLEANUP_TIMER	60
+
 enum {
 	CHANSERV_STAT_JOIN = 0,
 	CHANSERV_STAT_PART,
@@ -54,7 +57,7 @@
 	char *who;
 	int stats[CHANSERV_STAT_LEN];
 	time_t last_event_time[CHANSERV_STAT_LEN];
-	time_t join_time;
+	time_t last_event;
 } chanserv_member_stats_t;
 
 typedef struct chanserv_channel_stats {
Index: eggdrop1.9/modules/server/input.c
diff -u eggdrop1.9/modules/server/input.c:1.37 eggdrop1.9/modules/server/input.c:1.38
--- eggdrop1.9/modules/server/input.c:1.37	Mon Oct  4 10:48:30 2004
+++ eggdrop1.9/modules/server/input.c	Mon May 30 22:35:08 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: input.c,v 1.37 2004/10/04 15:48:30 stdarg Exp $";
+static const char rcsid[] = "$Id: input.c,v 1.38 2005/05/31 03:35:08 stdarg Exp $";
 #endif
 
 #include "server.h"
@@ -68,6 +68,7 @@
 	}
 
 	bind_check(BT_raw, NULL, msg.cmd, from_nick, from_uhost, u, msg.cmd, msg.nargs, msg.args);
+	irc_msg_cleanup(&msg);
 	return(0);
 }
 
----------------------- End of diff -----------------------



More information about the Changes mailing list