From 66da53eb85b9cf2a587b4de967cfeb11bc497ebd Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sat, 10 Feb 2018 16:01:30 +1000 Subject: [PATCH] lots of leaks fixed --- deps/aha/aha.c | 2 +- src/bluewave.c | 6 +++++- src/lua_glue.c | 17 ++++++++++++++--- src/mail_menu.c | 19 +++++++++++++++++++ src/users.c | 10 +++++----- src/www_msgs.c | 14 ++++++++++++-- 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/deps/aha/aha.c b/deps/aha/aha.c index faa53de..bac96b0 100644 --- a/deps/aha/aha.c +++ b/deps/aha/aha.c @@ -572,6 +572,6 @@ char * aha(char *input) //Footer if ((fc!=-1) || (bc!=-1) || (ul!=0) || (bo!=0) || (bl!=0)) append_output(&output, "\n", &size, &outat); - + free(unmangle_out); return output; } diff --git a/src/bluewave.c b/src/bluewave.c index 185fabd..dd97eaf 100644 --- a/src/bluewave.c +++ b/src/bluewave.c @@ -282,6 +282,7 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file fwrite(&mix, sizeof(MIX_REC), 1, mix_file); //} JAM_CloseMB(jb); + free(jb); free_message_headers(msghs); return totmsgs; } @@ -711,7 +712,8 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char sleep(1); } else { dolog("Failed to lock msg base!"); - JAM_CloseMB(jb); + JAM_CloseMB(jb); + free(jb); return 1; } } @@ -721,12 +723,14 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return -1; } else { JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); } return 0; } diff --git a/src/lua_glue.c b/src/lua_glue.c index 86102c4..58931d6 100644 --- a/src/lua_glue.c +++ b/src/lua_glue.c @@ -205,19 +205,21 @@ int l_messageFound(lua_State *L) { if (z != 0) { dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); JAM_CloseMB(jb); + free(jb); lua_pushnumber(L, 0); return 1; } if (jmh.Attribute & JAM_MSG_DELETED) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); lua_pushnumber(L, 0); return 1; } JAM_DelSubPacket(jsp); JAM_CloseMB(jb); - + free(jb); lua_pushnumber(L, 1); return 1; } @@ -247,9 +249,11 @@ int l_readMessageHdr(lua_State *L) { if (z != 0) { dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); JAM_CloseMB(jb); + free(jb); } else if (jmh.Attribute & JAM_MSG_DELETED) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); } else { for (z=0;zNumFields;z++) { if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { @@ -270,7 +274,8 @@ int l_readMessageHdr(lua_State *L) { } JAM_DelSubPacket(jsp); - JAM_CloseMB(jb); + JAM_CloseMB(jb); + free(jb); } if (subject == NULL) { subject = strdup("(No Subject)"); @@ -318,9 +323,11 @@ int l_readMessage(lua_State *L) { if (z != 0) { dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); JAM_CloseMB(jb); + free(jb); body = strdup("No Message"); } else if (jmh.Attribute & JAM_MSG_DELETED) { JAM_CloseMB(jb); + free(jb); body = strdup("No Message"); } else { body = (char *)malloc(jmh.TxtLen + 1); @@ -328,6 +335,7 @@ int l_readMessage(lua_State *L) { body[jmh.TxtLen] = '\0'; JAM_CloseMB(jb); + free(jb); } lua_pushstring(L, body); @@ -468,6 +476,7 @@ int l_postMessage(lua_State *L) { } else if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NETMAIL_AREA) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return 0; } @@ -479,7 +488,8 @@ int l_postMessage(lua_State *L) { sleep(1); } else { dolog("Failed to lock msg base!"); - JAM_CloseMB(jb); + JAM_CloseMB(jb); + free(jb); return 0; } } @@ -533,6 +543,7 @@ int l_postMessage(lua_State *L) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); } free(msg); diff --git a/src/mail_menu.c b/src/mail_menu.c index c2236bd..5fb1981 100644 --- a/src/mail_menu.c +++ b/src/mail_menu.c @@ -128,6 +128,7 @@ void free_message_headers(struct msg_headers *msghs) { if (msghs->msgs[i]->replyid != NULL) { free(msghs->msgs[i]->replyid); } + free(msghs->msgs[i]); } if (msghs->msg_count > 0) { free(msghs->msgs); @@ -354,9 +355,11 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r } else { JAM_CloseMB(jb); + free(jb); return NULL; } JAM_CloseMB(jb); + free(jb); return msghs; } @@ -1652,6 +1655,7 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno if (tolower(c) == 'r') { JAM_CloseMB(jb); + free(jb); if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { s_printf(get_string(113)); } else { @@ -1974,6 +1978,7 @@ int read_new_msgs(struct user_record *user, struct msg_headers *msghs) { all_unread = 1; } JAM_CloseMB(jb); + free(jb); if (all_unread == 0) { k = jlr.HighReadMsg; for (i=0;imsg_count;i++) { @@ -2023,6 +2028,7 @@ void read_mail(struct user_record *user) { all_unread = 1; } JAM_CloseMB(jb); + free(jb); s_printf(get_string(120), msghs->msg_count); s_readstring(buffer, 6); @@ -2287,6 +2293,7 @@ void post_message(struct user_record *user) { } if (z != 0) { JAM_CloseMB(jb); + free(jb); return; } @@ -2311,6 +2318,7 @@ void post_message(struct user_record *user) { JAM_DelSubPacket(jsp); free(msg); JAM_CloseMB(jb); + free(jb); } free(to); free(subject); @@ -2349,6 +2357,7 @@ void list_messages(struct user_record *user) { all_unread = 1; } JAM_CloseMB(jb); + free(jb); s_printf(get_string(125), msghs->msg_count); s_readstring(buffer, 6); @@ -2577,6 +2586,7 @@ void list_messages(struct user_record *user) { all_unread = 1; } JAM_CloseMB(jb); + free(jb); } } } @@ -2993,12 +3003,14 @@ void do_mail_scan(struct user_record *user, int oldscan) { if (JAM_ReadMBHeader(jb, &jbh) != 0) { JAM_CloseMB(jb); + free(jb); continue; } if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { if (jbh.ActiveMsgs == 0) { JAM_CloseMB(jb); + free(jb); continue; } if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NETMAIL_AREA) { @@ -3117,10 +3129,12 @@ void do_mail_scan(struct user_record *user, int oldscan) { } } else { JAM_CloseMB(jb); + free(jb); continue; } } JAM_CloseMB(jb); + free(jb); if (res) { break; } @@ -3257,6 +3271,7 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) { if (JAM_ReadMBHeader(jb, &jbh) != 0) { JAM_CloseMB(jb); + free(jb); return; } @@ -3301,6 +3316,7 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) { JAM_WriteLastRead(jb, gUser->id, &jlr); } JAM_CloseMB(jb); + free(jb); } void msgbase_reset_all_pointers(int readm) { @@ -3326,11 +3342,13 @@ int new_messages(struct user_record *user, int conference, int area) { } if (JAM_ReadMBHeader(jb, &jbh) != 0) { JAM_CloseMB(jb); + free(jb); return 0; } if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { if (jbh.ActiveMsgs == 0) { JAM_CloseMB(jb); + free(jb); return 0; } if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_NETMAIL_AREA) { @@ -3362,5 +3380,6 @@ int new_messages(struct user_record *user, int conference, int area) { } } JAM_CloseMB(jb); + free(jb); return count; } diff --git a/src/users.c b/src/users.c index 1026d08..f20e179 100644 --- a/src/users.c +++ b/src/users.c @@ -76,7 +76,7 @@ static int secLevel(void* user, const char* section, const char* name, } int save_user(struct user_record *user) { - char buffer[256]; + char buffer[PATH_MAX]; sqlite3 *db; sqlite3_stmt *res; int rc; @@ -84,7 +84,7 @@ int save_user(struct user_record *user) { char *update_sql = "UPDATE users SET password=?, salt=?, firstname=?," "lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=?, bwavepktno=?, archiver=?, protocol=?,nodemsgs=?,codepage=?,exteditor=?,bwavestyle=?,signature=?,autosig=? where loginname LIKE ?"; - sprintf(buffer, "%s/users.sq3", conf.bbs_path); + snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); @@ -99,7 +99,7 @@ int save_user(struct user_record *user) { if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, user->password, -1, 0); - sqlite3_bind_text(res, 2, user->salt, -1, 0); + sqlite3_bind_text(res, 2, user->salt, -1, 0); sqlite3_bind_text(res, 3, user->firstname, -1, 0); sqlite3_bind_text(res, 4, user->lastname, -1, 0); sqlite3_bind_text(res, 5, user->email, -1, 0); @@ -128,13 +128,13 @@ int save_user(struct user_record *user) { rc = sqlite3_step(res); - if (rc != SQLITE_DONE) { - + sqlite3_finalize(res); dolog("execution failed: %s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } + sqlite3_finalize(res); sqlite3_close(db); return 1; diff --git a/src/www_msgs.c b/src/www_msgs.c index 96ed912..c1ecdcf 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -174,6 +174,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); if (!jb) { free(page); + free_message_headers(mhrs); return NULL; } if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { @@ -181,7 +182,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i jlr.HighReadMsg = 0; } JAM_CloseMB(jb); - + free(jb); skip_f = mhrs->msg_count - skip; skip_t = mhrs->msg_count - skip - 50; if (skip_t < 0) { @@ -303,11 +304,13 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i z = JAM_ReadMsgHeader(jb, msg - 1, &jmh, &jsp); if (z != 0) { JAM_CloseMB(jb); + free(jb); return NULL; } if (jmh.Attribute & JAM_MSG_DELETED) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return NULL; } @@ -390,6 +393,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i free(replyid); } JAM_CloseMB(jb); + free(jb); return NULL; } } @@ -411,6 +415,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i JAM_WriteLastRead(jb, user->id, &jlr); JAM_CloseMB(jb); + free(jb); page = (char *)malloc(4096); max_len = 4096; @@ -868,11 +873,13 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, sleep(1); } else { JAM_CloseMB(jb); + free(jb); return 0; } } if (z != 0) { JAM_CloseMB(jb); + free(jb); return 0; } @@ -903,6 +910,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return 0; } body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer)); @@ -911,6 +919,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return 0; } @@ -924,6 +933,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return 0; } else { if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) { @@ -941,7 +951,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_DelSubPacket(jsp); JAM_CloseMB(jb); - + free(jb); return 1; } return 0;