[cvslog] (2005-06-24 19:01:07 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Fri Jun 24 13:01:08 CST 2005


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2005-06-24 19:01:07 UTC
Commited by: Darko Ilic <darko at onvol.net>

Modified files:
     lib/eggdrop/hash_table.c lib/eggdrop/hash_table.h
     lib/eggdrop/users.c

Log message:

- Introduced hash table flag HASH_TABLE_FREE_KEY. Useful with hashes that
  have their key created specifically for them (via strdup for example).
  It will signal hash_table_remove()/delete() to free(key) too.
  And there is already a beneficiary - irchosts_cache_ht will leak no more.

- Fixed leaks produced by userlist hash deletion - hash_table_delete() was
  not enough.

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/hash_table.c
diff -u eggdrop1.9/lib/eggdrop/hash_table.c:1.18 eggdrop1.9/lib/eggdrop/hash_table.c:1.19
--- eggdrop1.9/lib/eggdrop/hash_table.c:1.18	Thu Mar  3 12:44:47 2005
+++ eggdrop1.9/lib/eggdrop/hash_table.c	Fri Jun 24 14:00:57 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: hash_table.c,v 1.18 2005/03/03 18:44:47 stdarg Exp $";
+static const char rcsid[] = "$Id: hash_table.c,v 1.19 2005/06/24 19:00:57 darko Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -65,6 +65,8 @@
 		row = ht->rows+i;
 		for (entry = row->head; entry; entry = next) {
 			next = entry->next;
+			if (ht->flags & HASH_TABLE_FREE_KEY)
+				free(entry->key);
 			free(entry);
 		}
 	}
@@ -192,6 +194,9 @@
 			if (last) last->next = entry->next;
 			else row->head = entry->next;
 
+			if (ht->flags & HASH_TABLE_FREE_KEY)
+				free(entry->key);
+
 			free(entry);
 			ht->cells_in_use--;
 			return(0);
Index: eggdrop1.9/lib/eggdrop/hash_table.h
diff -u eggdrop1.9/lib/eggdrop/hash_table.h:1.6 eggdrop1.9/lib/eggdrop/hash_table.h:1.7
--- eggdrop1.9/lib/eggdrop/hash_table.h:1.6	Thu Mar  3 12:44:47 2005
+++ eggdrop1.9/lib/eggdrop/hash_table.h	Fri Jun 24 14:00:57 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: hash_table.h,v 1.6 2005/03/03 18:44:47 stdarg Exp $
+ * $Id: hash_table.h,v 1.7 2005/06/24 19:00:57 darko Exp $
  */
 
 #ifndef _EGG_HASH_TABLE_H_
@@ -26,6 +26,7 @@
 #define HASH_TABLE_INTS		2
 #define HASH_TABLE_MIXED	4
 #define HASH_TABLE_NORESIZE	8
+#define HASH_TABLE_FREE_KEY	16
 
 /* We automatically resize the table when (100 * cells in use) / max rows
  * exceeds this constant: */
Index: eggdrop1.9/lib/eggdrop/users.c
diff -u eggdrop1.9/lib/eggdrop/users.c:1.45 eggdrop1.9/lib/eggdrop/users.c:1.46
--- eggdrop1.9/lib/eggdrop/users.c:1.45	Sat May  7 23:40:12 2005
+++ eggdrop1.9/lib/eggdrop/users.c	Fri Jun 24 14:00:57 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: users.c,v 1.45 2005/05/08 04:40:12 stdarg Exp $";
+static const char rcsid[] = "$Id: users.c,v 1.46 2005/06/24 19:00:57 darko Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -75,6 +75,7 @@
 static int cache_rand_cleanup(const char *event);
 static int cache_user_del(user_t *u, const char *ircmask);
 static void append_setting(user_t *u, const char *chan, const char *flag_str, xml_node_t *extended);
+static int userlist_delete_walker(const void *key, void *dataptr, void *client_data);
 
 int user_init(void)
 {
@@ -82,7 +83,7 @@
 	/* Create hash tables. */
 	handle_ht = hash_table_create(NULL, NULL, USER_HASH_SIZE, HASH_TABLE_STRINGS);
 	uid_ht = hash_table_create(NULL, NULL, USER_HASH_SIZE, HASH_TABLE_INTS);
-	irchost_cache_ht = hash_table_create(NULL, NULL, HOST_HASH_SIZE, HASH_TABLE_STRINGS);
+	irchost_cache_ht = hash_table_create(NULL, NULL, HOST_HASH_SIZE, HASH_TABLE_STRINGS | HASH_TABLE_FREE_KEY);
 
 	/* And bind tables. */
 	BT_uflags = bind_table_add(BTN_USER_CHANGE_FLAGS, 4, "ssss", MATCH_MASK, BIND_STACKABLE);	/* DDD	*/
@@ -103,6 +104,8 @@
 	bind_table_del(BT_uset);
 	bind_table_del(BT_uflags);
 
+	hash_table_walk(uid_ht, userlist_delete_walker, NULL);
+
 	/* flush any pending user delete events */
 	garbage_run();
 
@@ -320,6 +323,11 @@
 	return(0);
 }
 
+static int userlist_delete_walker(const void *key, void *dataptr, void *client_data)
+{
+	return user_delete(*(user_t **)dataptr);
+}
+
 user_t *user_lookup_by_handle(const char *handle)
 {
 	user_t *u = NULL;
----------------------- End of diff -----------------------



More information about the Changes mailing list