AmendHub

jcs

/

subtext

/

amendments

/

235

session: Fix some memory leaks


jcs made amendment 235 2 months ago
--- session.c Sun Jul 31 22:39:39 2022 +++ session.c Mon Aug 1 22:27:59 2022 @@ -352,6 +352,8 @@ session_close(struct session *session) panic("session_close failed to find session to remove"); nsessions--; + if (session->user) + xfree(&session->user); xfree(&session); logger_update_title(); @@ -850,7 +852,7 @@ field_input_bail: short session_login(struct session *s) { - struct user *user; + struct user *user = NULL; char junk[SHA256_DIGEST_STRING_LENGTH]; char *username = NULL, *password = NULL; size_t len; @@ -894,17 +896,17 @@ session_login(struct session *s) username); xfree(&username); return AUTH_USER_SIGNUP; - } else { - user = user_find_by_username(username); - - if (!user && user_username_is_banned(username)) { - session_log(s, "Attempted login as banned username %s", - username); - s->ban_node_source = 1; - goto login_bail; - } } + user = user_find_by_username(username); + + if (!user && user_username_is_banned(username)) { + session_log(s, "Attempted login as banned username %s", + username); + s->ban_node_source = 1; + goto login_bail; + } + if (s->autologin_username[0]) { if (user) { xfree(&username); @@ -963,6 +965,9 @@ session_login(struct session *s) uthread_msleep(60); session_printf(s, "Login incorrect\r\n"); session_flush(s); + + if (user) + xfree(&user); } login_bail: