From 2cd7da76b8fb948bdb4be48367e5374e2fe39757 Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Wed, 5 Oct 2005 01:53:30 +0000 Subject: [PATCH] Do not leak connection class structures after they are removed from ircd.conf. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1511 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- ChangeLog | 13 +++++++++++++ include/class.h | 4 +++- ircd/class.c | 18 ++++++++++-------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index a563a68..914677f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-10-04 Michael Poole + [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 * ircd/m_kick.c (ms_kick): If the kick target is join-delayed, diff --git a/include/class.h b/include/class.h index 816576d..5a9647d 100644 --- a/include/class.h +++ b/include/class.h @@ -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); diff --git a/ircd/class.c b/ircd/class.c index 7415805..d4ddff9 100644 --- a/ircd/class.c +++ b/ircd/class.c @@ -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. -- 2.20.1