Author: net <simms@LUCIDA.QC.CA> (by way of Kev <klmitch@mit.edu>)
authorKevin L. Mitchell <klmitch@mit.edu>
Fri, 1 Dec 2000 16:08:47 +0000 (16:08 +0000)
committerKevin L. Mitchell <klmitch@mit.edu>
Fri, 1 Dec 2000 16:08:47 +0000 (16:08 +0000)
Log message:

Do a freelist for struct Motd

Testing done:

I (Kev) tested this, and it works, and there does not appear to be any form
of memory leak.

git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@319 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
ircd/motd.c

index 5ab8c35e96ce0f906573268541296cb09a3d75d2..e966b5a6257f448fa72e3cbd73ada264f274f6a2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2000-12-01  net  <simms@LUCIDA.QC.CA>
+
+       * ircd/motd.c: add a freelist for struct Motds
+
 2000-11-30  Kevin L. Mitchell  <klmitch@mit.edu>
 
        * ircd/s_stats.c (report_feature_list): report features--only
index 503b530ffbb5f7295e8aaa4298aeb48862fe63f0..9a027e0750609d239f852d028c9b13e17abe7493 100644 (file)
@@ -50,6 +50,7 @@ static struct {
   struct Motd* local;
   struct Motd* remote;
   struct Motd* other;
+  struct Motd* freelist;
 } MotdList;
 
 /* Create a struct Motd and initialize it */
@@ -73,7 +74,11 @@ motd_create(const char *hostmask, const char *path, int maxcount)
   }
 
   /* allocate memory and initialize the structure */
-  tmp = (struct Motd *)MyMalloc(sizeof(struct Motd));
+  if (MotdList.freelist) {
+    tmp = MotdList.freelist;
+    MotdList.freelist = tmp->next;
+  } else
+    tmp = (struct Motd *)MyMalloc(sizeof(struct Motd));
 
   tmp->next = 0;
   tmp->type = type;
@@ -180,7 +185,8 @@ motd_destroy(struct Motd *motd)
   if (motd->cache) /* drop the cache */
     motd_decache(motd);
 
-  MyFree(motd); /* free the structure */
+  motd->next = MotdList.freelist;
+  MotdList.freelist = motd;
 }
 
 /* We use this routine to look up the struct Motd to send to any given