- Fixed a few memory related issues, mostly to do with conf handling.
authorAndrew Miller <a1kmm@amxl.com>
Mon, 1 Jul 2002 07:04:19 +0000 (07:04 +0000)
committerAndrew Miller <a1kmm@amxl.com>
Mon, 1 Jul 2002 07:04:19 +0000 (07:04 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@784 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
include/ircd_alloc.h
ircd/class.c
ircd/engine_poll.c
ircd/ircd_parser.y

index 8cccebbe287771f5da1959bd0ac5ec2655fce116..3f156caafc3999e914de1e86f24618975a6886d4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2002-07-01 Andrew Miller <a1kmm@mware.virtualave.net>
+       * include/ircd_alloc.h (MyFree): Accept NULL pointers to do nothing
+       with, this is used quite a lot.
+       * ircd/class.c (make_class): Initialise the ref_count to 1 so that
+       we don't leak.
+       * ircd/class.c (add_class): When updating a class, free the old name
+       first to prevent leakage.
+       * ircd/class.c (class_delete_marked): Decrement the ref_count for the
+       class after it is removed from the linked list.
+       * ircd/ircd_parser.y: Changed a free to MyFree().
+       * ircd/ircd_parser.y: Removed a few debugging messages.
+
 2002-07-01 Andrew Miller <a1kmm@mware.virtualave.net>
        * s_bsd.c (read_packet): Our daily addition to the list of entities to
        treat as servers - Connecting servers.
index 1569d7650865b40d545b70f813166c975df9b17e..f78ad0df9793ae0edc78ca1b1a977f7e59b1d8dd 100644 (file)
@@ -38,7 +38,8 @@ extern void set_nomem_handler(OutOfMemoryHandler handler);
   DoMallocZero(size * nelem, "calloc", __FILE__, __LINE__)
 
 #define MyFree(p) \
-  DoFree(p, __FILE__, __LINE__)
+  if (p) \
+    DoFree(p, __FILE__, __LINE__)
 
 /* No realloc because it is not currently used, and it is not really the
  * nicest function to be using anyway(i.e. its evil if you want it
index 27ca816a1071f790c4847bb048d0d14682292d05..ba5d7191d29eebe78874eb6ca74955df8bfce70d 100644 (file)
@@ -52,6 +52,7 @@ struct ConnectionClass* make_class(void)
   struct ConnectionClass *tmp;
 
   tmp = (struct ConnectionClass*) MyMalloc(sizeof(struct ConnectionClass));
+  tmp->ref_count = 1;
   assert(0 != tmp);
   ++connClassAllocCount;
   return tmp;
@@ -59,10 +60,11 @@ struct ConnectionClass* make_class(void)
 
 void free_class(struct ConnectionClass* p)
 {
-  if (p) {
+  if (p)
+  {
     assert(0 == p->valid);
     if (p->cc_name)
-     MyFree(p->cc_name);
+      MyFree(p->cc_name);
     MyFree(p);
     --connClassAllocCount;
   }
@@ -123,9 +125,10 @@ void class_delete_marked(void)
      */
     if (cl->valid)
       prev = cl;
-    else {
+    else
+    {
       prev->next = cl->next;
-      if (0 == cl->ref_count)
+      if (0 == --cl->ref_count)
         free_class(cl);
     }
   }
@@ -198,7 +201,11 @@ void add_class(char *name, unsigned int ping, unsigned int confreq,
     t->next = p;
   }
   else
+  {
+    if (ConClass(t) != NULL)
+      MyFree(ConClass(t));
     p = t;
+  }
   Debug((DEBUG_DEBUG, "Add Class %s: cf: %u pf: %u ml: %u sq: %d",
          name, confreq, ping, maxli, sendq));
   ConClass(p) = name;
index a166d4f2482d248730f3d38aaad79ce252114a78..01bd0a3bb6fd34292984b4fcdff2806c838ed09e 100644 (file)
@@ -303,7 +303,7 @@ engine_loop(struct Generators* gen)
        }
       }
 
-      assert(!(pollfdList[i].revents & POLLERR));
+      /* assert(!(pollfdList[i].revents & POLLERR)); */
 
 #ifdef POLLHUP
       if (pollfdList[i].revents & POLLHUP) { /* hang-up on socket */
index 44220713c6750cf50d1fa614db1f8761e42ef719..8db80e66e084f8d839ce2ddaea9e43dda145bad1 100644 (file)
@@ -302,46 +302,46 @@ adminlocation: LOCATION '=' QSTRING ';'
 admincontact: CONTACT '=' QSTRING ';'
 {
  if (localConf.contact != NULL)
-  free(localConf.contact);
+   MyFree(localConf.contact);
  DupString(localConf.contact, yylval.text);
 };
 
 classblock: CLASS {
- name = NULL;
- tping = 90;
- tconn = 0;
- maxlinks = 0;
- sendq = 0;
 name = NULL;
 tping = 90;
 tconn = 0;
 maxlinks = 0;
 sendq = 0;
 } '{' classitems '}'
 {
- if (name != NULL)
- {
-  add_class(name, tping, tconn, maxlinks, sendq);
- }
 if (name != NULL)
 {
+   add_class(name, tping, tconn, maxlinks, sendq);
 }
 } ';';
 classitems: classitem classitems | classitem;
 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
            classsendq;
 classname: NAME '=' QSTRING ';'
 {
- MyFree(name);
- DupString(name, yylval.text);
 MyFree(name);
 DupString(name, yylval.text);
 };
 classpingfreq: PINGFREQ '=' timespec ';'
 {
- tping = yylval.num;
 tping = yylval.num;
 };
 classconnfreq: CONNECTFREQ '=' timespec ';'
 {
- tconn = yylval.num;
 tconn = yylval.num;
 };
 classmaxlinks: MAXLINKS '=' expr ';'
 {
- maxlinks = yylval.num;
 maxlinks = yylval.num;
 };
 classsendq: SENDQ '=' sizespec ';'
 {
- sendq = yylval.num;
 sendq = yylval.num;
 };
 
 connectblock: CONNECT
@@ -355,27 +355,25 @@ connectblock: CONNECT
      /*ccount < MAXCONFLINKS &&*/ !strchr(host, '*') &&
      !strchr(host, '?'))
  {
-  aconf = MyMalloc(sizeof(*aconf));
-  aconf->status = CONF_SERVER;
-  aconf->name = name;
-  aconf->passwd = pass;
-  aconf->conn_class = class;
-  aconf->port = port;
-  aconf->status = CONF_SERVER;
-  aconf->host = host;
-  aconf->next = GlobalConfList;
-  aconf->ipnum.s_addr = INADDR_NONE;
-  lookup_confhost(aconf);
-  GlobalConfList = aconf;
-  printf("Server added: %s\n", name);
-  /* ccount++; -- XXX fixme --- A1kmm */
+   aconf = make_conf();
+   aconf->status = CONF_SERVER;
+   aconf->name = name;
+   aconf->passwd = pass;
+   aconf->conn_class = class;
+   aconf->port = port;
+   aconf->status = CONF_SERVER;
+   aconf->host = host;
+   aconf->next = GlobalConfList;
+   aconf->ipnum.s_addr = INADDR_NONE;
+   lookup_confhost(aconf);
+   GlobalConfList = aconf;
  }
  else
  {
-  MyFree(name);
-  MyFree(pass);
-  MyFree(host);
-  name = pass = host = NULL;
+   MyFree(name);
+   MyFree(pass);
+   MyFree(host);
+   name = pass = host = NULL;
  }
 }';';
 connectitems: connectitem connectitems | connectitem;
@@ -477,7 +475,6 @@ operblock: OPER
 {
   if (aconf->name != NULL && aconf->passwd != NULL && aconf->host != NULL)
   {
-    log_write(LS_CONFIG, L_ERROR, 0, "added an oper block for host %s", aconf->host);
     aconf->next = GlobalConfList;
     GlobalConfList = aconf;
   }