Do not leak connection class structures after they are removed from ircd.conf.
authorMichael Poole <mdpoole@troilus.org>
Wed, 5 Oct 2005 01:53:30 +0000 (01:53 +0000)
committerMichael Poole <mdpoole@troilus.org>
Wed, 5 Oct 2005 01:53:30 +0000 (01:53 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1511 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
include/class.h
ircd/class.c

index a563a68f7651d730a778039518036782a56f1354..914677fb2966baca88b949253ee0cbb718789335 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-10-04  Michael Poole <mdpoole@troilus.org>
+       [Based on a patch by Jukka Ollila]
+
+       * include/class.h (find_class): Rename to do_find_class().
+
+       * ircd/class.c (class_delete_marked): Keep invalid classes in list
+       until next rehash.
+       (add_class): Use new parameter to do_find_class() to allow a class
+       to be "resurrected".
+       (find_class): Rename.
+       (report_classes): Use 'y' instead of 'Y' when reporting invalid
+       classes.
+
 2005-10-01  Michael Poole <mdpoole@troilus.org>
 
        * ircd/m_kick.c (ms_kick): If the kick target is join-delayed,
index 816576db30dc15c36e43ceb57d04852fe5cc9468..5a9647d2750c6de26616a1ba9425432e2cc0cb89 100644 (file)
@@ -86,6 +86,8 @@ struct ConnectionClass {
 #define ConfLinks(x)    ((x)->conn_class->ref_count)
 /** Get default usermode for ConfItem \a x. */
 #define ConfUmode(x)    ((x)->conn_class->default_umode)
+/** Find a valid configuration class by name. */
+#define find_class(name) do_find_class((name), 0)
 
 /*
  * Proto types
@@ -97,7 +99,7 @@ extern const struct ConnectionClass* get_class_list(void);
 extern void class_mark_delete(void);
 extern void class_delete_marked(void);
 
-extern struct ConnectionClass *find_class(const char *name);
+extern struct ConnectionClass *do_find_class(const char *name, int extras);
 extern struct ConnectionClass *make_class(void);
 extern void free_class(struct ConnectionClass * tmp);
 extern char *get_conf_class(const struct ConfItem *aconf);
index 7415805195574156b751c66ddda76492edca3826..d4ddff9b95c4079e8687dacfd47c99fc28e2a152 100644 (file)
@@ -136,13 +136,12 @@ void class_delete_marked(void)
     /*
      * unlink marked classes, delete unreferenced ones
      */
-    if (cl->valid)
+    if (cl->valid || Links(cl) > 1)
       prev = cl;
     else
     {
       prev->next = cl->next;
-      if (0 == --cl->ref_count)
-        free_class(cl);
+      free_class(cl);
     }
   }
 }
@@ -215,7 +214,7 @@ void add_class(char *name, unsigned int ping, unsigned int confreq,
   Debug((DEBUG_DEBUG, "Add Class %s: cf: %u pf: %u ml: %u sq: %d",
          name, confreq, ping, maxli, sendq));
   assert(name != NULL);
-  p = find_class(name);
+  p = do_find_class(name, 1);
   if (!p)
     p = make_class();
   else
@@ -231,13 +230,16 @@ void add_class(char *name, unsigned int ping, unsigned int confreq,
 
 /** Find a connection class by name.
  * @param[in] name Name of connection class to search for.
+ * @param[in] extras If non-zero, include unreferenced classes.
  * @return Pointer to connection class structure (or NULL if none match).
  */
-struct ConnectionClass* find_class(const char *name)
+struct ConnectionClass* do_find_class(const char *name, int extras)
 {
   struct ConnectionClass *cltmp;
 
   for (cltmp = connClassList; cltmp; cltmp = cltmp->next) {
+    if (!cltmp->valid || !extras)
+      continue;
     if (!ircd_strcmp(ConClass(cltmp), name))
       return cltmp;
   }
@@ -256,9 +258,9 @@ report_classes(struct Client *sptr, const struct StatDesc *sd,
   struct ConnectionClass *cltmp;
 
   for (cltmp = connClassList; cltmp; cltmp = cltmp->next)
-    send_reply(sptr, RPL_STATSYLINE, 'Y', ConClass(cltmp), PingFreq(cltmp),
-              ConFreq(cltmp), MaxLinks(cltmp), MaxSendq(cltmp),
-              Links(cltmp) - 1);
+    send_reply(sptr, RPL_STATSYLINE, (cltmp->valid ? 'Y' : 'y'),
+               ConClass(cltmp), PingFreq(cltmp), ConFreq(cltmp),
+               MaxLinks(cltmp), MaxSendq(cltmp), Links(cltmp) - 1);
 }
 
 /** Return maximum SendQ length for a client.