Skip to content

Commit 16e34f4

Browse files
committed
Fix memory leak on groupchat window creation failure
Also do some safety null checks in group and conferences cleanup functions
1 parent 7470a9a commit 16e34f4

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

Diff for: src/conference.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,22 @@ void conference_set_title(ToxWindow *self, uint32_t conferencesnum, const char *
142142

143143
static void kill_conference_window(ToxWindow *self)
144144
{
145+
if (self == NULL) {
146+
return;
147+
}
148+
145149
ChatContext *ctx = self->chatwin;
146150

147-
log_disable(ctx->log);
148-
line_info_cleanup(ctx->hst);
149-
delwin(ctx->linewin);
150-
delwin(ctx->history);
151-
delwin(ctx->sidebar);
152-
free(ctx->log);
153-
free(ctx);
151+
if (ctx != NULL) {
152+
log_disable(ctx->log);
153+
line_info_cleanup(ctx->hst);
154+
delwin(ctx->linewin);
155+
delwin(ctx->history);
156+
delwin(ctx->sidebar);
157+
free(ctx->log);
158+
free(ctx);
159+
}
160+
154161
free(self->help);
155162
kill_notifs(self->active_box);
156163
del_window(self);

Diff for: src/groupchats.c

+17-7
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,24 @@ void groupchat_rejoin(ToxWindow *self, Tox *m)
213213

214214
static void kill_groupchat_window(ToxWindow *self)
215215
{
216+
if (self == NULL) {
217+
return;
218+
}
219+
216220
ChatContext *ctx = self->chatwin;
217221

218-
log_disable(ctx->log);
219-
line_info_cleanup(ctx->hst);
220-
delwin(ctx->linewin);
221-
delwin(ctx->history);
222-
delwin(ctx->sidebar);
223-
free(ctx->log);
224-
free(ctx);
222+
if (ctx != NULL) {
223+
log_disable(ctx->log);
224+
line_info_cleanup(ctx->hst);
225+
delwin(ctx->linewin);
226+
delwin(ctx->history);
227+
delwin(ctx->sidebar);
228+
free(ctx->log);
229+
free(ctx);
230+
}
231+
225232
free(self->help);
233+
kill_notifs(self->active_box);
226234
del_window(self);
227235
}
228236

@@ -357,6 +365,8 @@ int init_groupchat_win(Tox *m, uint32_t groupnumber, const char *groupname, size
357365
}
358366
}
359367

368+
kill_groupchat_window(self);
369+
360370
return -1;
361371
}
362372

Diff for: src/line_info.c

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ void line_info_reset_start(ToxWindow *self, struct history *hst)
8585

8686
void line_info_cleanup(struct history *hst)
8787
{
88+
if (hst == NULL) {
89+
return;
90+
}
91+
8892
struct line_info *tmp1 = hst->line_root;
8993

9094
while (tmp1) {

0 commit comments

Comments
 (0)