Skip to content

Commit 341477a

Browse files
Fix mem leak
Found by: @Robby-, Mystery-X Patch by: thommey and michaelortmann Fix mem leaks by fixing tcl ref counting (also preventing premature free) / tcl object instantiation
1 parent 541e8ac commit 341477a

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/mod/irc.mod/chan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2866,7 +2866,7 @@ static int irc_isupport(char *key, char *isset_str, char *value)
28662866

28672867
static int gotrawt(char *from, char *msg, Tcl_Obj *tags) {
28682868
Tcl_Obj *valueobj;
2869-
if (TCL_OK != Tcl_DictObjGet(interp, tags, Tcl_NewStringObj("account", -1), &valueobj)) {
2869+
if (TCL_OK != Tcl_DictObjGet(interp, tags, tcl_account, &valueobj)) {
28702870
putlog(LOG_MISC, "*", "ERROR: irc:rawt called with invalid dictionary");
28712871
return 0;
28722872
}

src/mod/irc.mod/irc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ static int include_lk = 1; /* For correct calculation in real_add_mode. */
6565

6666
static char opchars[8]; /* the chars in a /who reply meaning op */
6767

68+
static Tcl_Obj *tcl_account;
69+
6870
#include "chan.c"
6971
#include "mode.c"
7072
#include "cmdsirc.c"
@@ -1347,6 +1349,7 @@ static char *irc_close()
13471349
rem_builtins(H_msg, C_msg);
13481350
rem_builtins(H_raw, irc_raw);
13491351
rem_builtins(H_rawt, irc_rawt);
1352+
Tcl_DecrRefCount(tcl_account);
13501353
rem_builtins(H_isupport, irc_isupport_binds);
13511354
rem_tcl_commands(tclchan_cmds);
13521355
rem_help_reference("irc.help");
@@ -1455,6 +1458,8 @@ char *irc_start(Function *global_funcs)
14551458
add_builtins(H_dcc, irc_dcc);
14561459
add_builtins(H_msg, C_msg);
14571460
add_builtins(H_raw, irc_raw);
1461+
tcl_account = Tcl_NewStringObj("account", -1);
1462+
Tcl_IncrRefCount(tcl_account);
14581463
add_builtins(H_rawt, irc_rawt);
14591464
add_builtins(H_isupport, irc_isupport_binds);
14601465
add_tcl_commands(tclchan_cmds);

src/mod/server.mod/servmsg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static int monitor_del (char *nick);
4545
static int monitor_show(Tcl_Obj *mlist, int mode, char *nick);
4646
static void monitor_clear();
4747
int account_notify = 1, extended_join = 1, account_tag = 0;
48-
Tcl_Obj *ncapeslist;
4948

5049
/* We try to change to a preferred unique nick here. We always first try the
5150
* specified alternate nick. If that fails, we repeatedly modify the nick
@@ -1223,6 +1222,7 @@ static void server_activity(int idx, char *tagmsg, int len)
12231222
int ret;
12241223
Tcl_Obj *tagdict = Tcl_NewDictObj();
12251224

1225+
Tcl_IncrRefCount(tagdict);
12261226
if (trying_server) {
12271227
strcpy(dcc[idx].nick, "(server)");
12281228
putlog(LOG_SERV, "*", "Connected to %s", dcc[idx].host);
@@ -1268,6 +1268,7 @@ static void server_activity(int idx, char *tagmsg, int len)
12681268
if (!ret) {
12691269
check_tcl_raw(from, code, msgptr);
12701270
}
1271+
Tcl_DecrRefCount(tagdict);
12711272
}
12721273

12731274
static int gotping(char *from, char *msg)
@@ -2359,7 +2360,6 @@ static void server_resolve_success(int servidx)
23592360
/* Start alternate nicks from the beginning */
23602361
altnick_char = 0;
23612362
check_tcl_event("preinit-server");
2362-
ncapeslist = Tcl_NewListObj(0, NULL);
23632363
/* See if server supports CAP command */
23642364
dprintf(DP_MODE, "CAP LS 302\n");
23652365
if (pass[0])

0 commit comments

Comments
 (0)