From b914997a1c81cb249a2debfb8094bd87f2bec363 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 2 Apr 2023 08:24:00 +0200 Subject: [PATCH] Update cmode.free_param definition to fix memleak due to yesterdays commit. And update release notes technical note so it actually refers to the correct channel mode function :D --- doc/RELEASE-NOTES.md | 7 ++++--- include/modules.h | 8 +++++--- src/api-channelmode.c | 6 +++--- src/modules/chanmodes/floodprot.c | 6 +++--- src/modules/chanmodes/history.c | 4 ++-- src/modules/chanmodes/key.c | 4 ++-- src/modules/chanmodes/limit.c | 4 ++-- src/modules/chanmodes/link.c | 4 ++-- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/doc/RELEASE-NOTES.md b/doc/RELEASE-NOTES.md index 5168ec416..4e9461348 100644 --- a/doc/RELEASE-NOTES.md +++ b/doc/RELEASE-NOTES.md @@ -74,9 +74,10 @@ in progress and not a stable version. directive now accepts wildcards, eg `blacklist-module rpc/*;` ### Developers and protocol: -* The `cmode.put_param` is now `int` instead of `void`. You normally - `return 0` here. You can `return 1` if you resist freeing, which is - rare and only used by `+F` with set::anti-flood::channel::default-profile. +* The `cmode.free_param` definition changed. It now has an extra argument + `int soft` and for return value you will normally `return 0` here. + You can `return 1` if you resist freeing, which is rare and only used by + `+F` with set::anti-flood::channel::default-profile. * JSON-RPC supports [UNIX domain sockets](https://www.unrealircd.org/docs/JSON-RPC:Technical_documentation#UNIX_domain_socket) for making RPC calls. If those are used, we now split on `\n` (newline) diff --git a/include/modules.h b/include/modules.h index 5acb2eaf4..168c0f956 100644 --- a/include/modules.h +++ b/include/modules.h @@ -285,11 +285,13 @@ struct Cmode { /** Free and remove parameter from list. * This function pointer is NULL (unused) for modes without parameters. - * @param parastruct The parameter struct + * @param parastruct The parameter struct + * @param soft This is set to 1 if you may 'resist freeing' + * (used by floodprot module to have active F profile even if -F). * @returns Normally return 0, must return 1 if it 'resisted' freeing. * @note In most cases you will just call safe_free() on 'list' */ - int (*free_param)(void *parastruct); + int (*free_param)(void *parastruct, int soft); /** duplicate a struct and return a pointer to duplicate. * This function pointer is NULL (unused) for modes without parameters. @@ -348,7 +350,7 @@ typedef struct { void * (*put_param)(void *, const char *); const char * (*get_param)(void *); const char * (*conv_param)(const char *, Client *, Channel *); - int (*free_param)(void *); + int (*free_param)(void *, int); void * (*dup_struct)(void *); int (*sjoin_check)(Channel *, void *, void *); char local; diff --git a/src/api-channelmode.c b/src/api-channelmode.c index e6208b4d2..3552c45a2 100644 --- a/src/api-channelmode.c +++ b/src/api-channelmode.c @@ -534,7 +534,7 @@ static void unload_extcmode_commit(Cmode *cmode) } free_message_tags(mtags); - cmode->free_param(GETPARASTRUCT(channel, cmode->letter)); + cmode->free_param(GETPARASTRUCT(channel, cmode->letter), 0); channel->mode.mode &= ~cmode->mode; } } @@ -627,7 +627,7 @@ void cm_putparameter(Channel *channel, char mode, const char *str) */ void cm_freeparameter(Channel *channel, char mode) { - int n = GETPARAMHANDLERBYLETTER(mode)->free_param(GETPARASTRUCT(channel, mode)); + int n = GETPARAMHANDLERBYLETTER(mode)->free_param(GETPARASTRUCT(channel, mode), 1); if (n == 0) GETPARASTRUCT(channel, mode) = NULL; } @@ -714,7 +714,7 @@ void extcmode_free_paramlist(void **ar) handler = GETPARAMHANDLERBYSLOT(i); if (!handler) continue; /* nothing here... */ - handler->free_param(ar[handler->param_slot]); + handler->free_param(ar[handler->param_slot], 0); ar[handler->param_slot] = NULL; } } diff --git a/src/modules/chanmodes/floodprot.c b/src/modules/chanmodes/floodprot.c index 8bd96c26c..17894d5d5 100644 --- a/src/modules/chanmodes/floodprot.c +++ b/src/modules/chanmodes/floodprot.c @@ -152,7 +152,7 @@ int cmodef_is_ok(Client *client, Channel *channel, char mode, const char *para, void *cmodef_put_param(void *r_in, const char *param); const char *cmodef_get_param(void *r_in); const char *cmodef_conv_param(const char *param_in, Client *client, Channel *channel); -int cmodef_free_param(void *r); +int cmodef_free_param(void *r, int soft); void *cmodef_dup_struct(void *r_in); int cmodef_sjoin_check(Channel *channel, void *ourx, void *theirx); int cmodef_profile_is_ok(Client *client, Channel *channel, char mode, const char *param, int type, int what); @@ -879,14 +879,14 @@ const char *cmodef_conv_param(const char *param_in, Client *client, Channel *cha return retbuf; } -int cmodef_free_param(void *r) +int cmodef_free_param(void *r, int soft) { ChannelFloodProtection *fld = (ChannelFloodProtection *)r; if (!fld) return 0; - if (fld->profile && cfg.default_profile) + if (soft && fld->profile && cfg.default_profile) { /* Resist freeing */ if (strcmp(fld->profile, cfg.default_profile)) diff --git a/src/modules/chanmodes/history.c b/src/modules/chanmodes/history.c index e3b4db160..4883cdcc9 100644 --- a/src/modules/chanmodes/history.c +++ b/src/modules/chanmodes/history.c @@ -50,7 +50,7 @@ int history_chanmode_is_ok(Client *client, Channel *channel, char mode, const ch void *history_chanmode_put_param(void *r_in, const char *param); const char *history_chanmode_get_param(void *r_in); const char *history_chanmode_conv_param(const char *param, Client *client, Channel *channel); -int history_chanmode_free_param(void *r); +int history_chanmode_free_param(void *r, int soft); void *history_chanmode_dup_struct(void *r_in); int history_chanmode_sjoin_check(Channel *channel, void *ourx, void *theirx); int history_channel_destroy(Channel *channel, int *should_destroy); @@ -576,7 +576,7 @@ const char *history_chanmode_get_param(void *h_in) } /** Free channel mode */ -int history_chanmode_free_param(void *r) +int history_chanmode_free_param(void *r, int soft) { safe_free(r); return 0; diff --git a/src/modules/chanmodes/key.c b/src/modules/chanmodes/key.c index 4e8b9c8c7..030a2140f 100644 --- a/src/modules/chanmodes/key.c +++ b/src/modules/chanmodes/key.c @@ -45,7 +45,7 @@ int cmode_key_is_ok(Client *client, Channel *channel, char mode, const char *par void *cmode_key_put_param(void *r_in, const char *param); const char *cmode_key_get_param(void *r_in); const char *cmode_key_conv_param(const char *param_in, Client *client, Channel *channel); -int cmode_key_free_param(void *r); +int cmode_key_free_param(void *r, int soft); void *cmode_key_dup_struct(void *r_in); int cmode_key_sjoin_check(Channel *channel, void *ourx, void *theirx); int is_valid_key(const char *key); @@ -162,7 +162,7 @@ const char *cmode_key_conv_param(const char *param, Client *client, Channel *cha return retbuf; } -int cmode_key_free_param(void *r) +int cmode_key_free_param(void *r, int soft) { safe_free(r); return 0; diff --git a/src/modules/chanmodes/limit.c b/src/modules/chanmodes/limit.c index 309ba8071..ab2855d1d 100644 --- a/src/modules/chanmodes/limit.c +++ b/src/modules/chanmodes/limit.c @@ -48,7 +48,7 @@ int cmode_limit_is_ok(Client *client, Channel *channel, char mode, const char *p void *cmode_limit_put_param(void *r_in, const char *param); const char *cmode_limit_get_param(void *r_in); const char *cmode_limit_conv_param(const char *param_in, Client *client, Channel *channel); -int cmode_limit_free_param(void *r); +int cmode_limit_free_param(void *r, int soft); void *cmode_limit_dup_struct(void *r_in); int cmode_limit_sjoin_check(Channel *channel, void *ourx, void *theirx); int transform_channel_limit(const char *param); @@ -159,7 +159,7 @@ const char *cmode_limit_conv_param(const char *param, Client *client, Channel *c return retbuf; } -int cmode_limit_free_param(void *r) +int cmode_limit_free_param(void *r, int soft) { safe_free(r); return 0; diff --git a/src/modules/chanmodes/link.c b/src/modules/chanmodes/link.c index 2702637a9..cb609f962 100644 --- a/src/modules/chanmodes/link.c +++ b/src/modules/chanmodes/link.c @@ -49,7 +49,7 @@ int cmodeL_is_ok(Client *client, Channel *channel, char mode, const char *para, void *cmodeL_put_param(void *r_in, const char *param); const char *cmodeL_get_param(void *r_in); const char *cmodeL_conv_param(const char *param_in, Client *client, Channel *channel); -int cmodeL_free_param(void *r); +int cmodeL_free_param(void *r, int soft); void *cmodeL_dup_struct(void *r_in); int cmodeL_sjoin_check(Channel *channel, void *ourx, void *theirx); @@ -178,7 +178,7 @@ const char *cmodeL_conv_param(const char *param, Client *client, Channel *channe return param; } -int cmodeL_free_param(void *r) +int cmodeL_free_param(void *r, int soft) { safe_free(r); return 0;