lots of leaks fixed

This commit is contained in:
Andrew Pamment 2018-02-10 16:01:30 +10:00
parent d5d61a8cc6
commit 66da53eb85
6 changed files with 56 additions and 12 deletions

2
deps/aha/aha.c vendored
View File

@ -572,6 +572,6 @@ char * aha(char *input)
//Footer //Footer
if ((fc!=-1) || (bc!=-1) || (ul!=0) || (bo!=0) || (bl!=0)) if ((fc!=-1) || (bc!=-1) || (ul!=0) || (bo!=0) || (bl!=0))
append_output(&output, "</span>\n", &size, &outat); append_output(&output, "</span>\n", &size, &outat);
free(unmangle_out);
return output; return output;
} }

View File

@ -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); fwrite(&mix, sizeof(MIX_REC), 1, mix_file);
//} //}
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
free_message_headers(msghs); free_message_headers(msghs);
return totmsgs; return totmsgs;
} }
@ -711,7 +712,8 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
sleep(1); sleep(1);
} else { } else {
dolog("Failed to lock msg base!"); dolog("Failed to lock msg base!");
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 1; return 1;
} }
} }
@ -721,12 +723,14 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return -1; return -1;
} else { } else {
JAM_UnlockMB(jb); JAM_UnlockMB(jb);
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
} }
return 0; return 0;
} }

View File

@ -205,19 +205,21 @@ int l_messageFound(lua_State *L) {
if (z != 0) { if (z != 0) {
dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb));
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
lua_pushnumber(L, 0); lua_pushnumber(L, 0);
return 1; return 1;
} }
if (jmh.Attribute & JAM_MSG_DELETED) { if (jmh.Attribute & JAM_MSG_DELETED) {
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
lua_pushnumber(L, 0); lua_pushnumber(L, 0);
return 1; return 1;
} }
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
lua_pushnumber(L, 1); lua_pushnumber(L, 1);
return 1; return 1;
} }
@ -247,9 +249,11 @@ int l_readMessageHdr(lua_State *L) {
if (z != 0) { if (z != 0) {
dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb));
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
} else if (jmh.Attribute & JAM_MSG_DELETED) { } else if (jmh.Attribute & JAM_MSG_DELETED) {
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
} else { } else {
for (z=0;z<jsp->NumFields;z++) { for (z=0;z<jsp->NumFields;z++) {
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
@ -270,7 +274,8 @@ int l_readMessageHdr(lua_State *L) {
} }
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
} }
if (subject == NULL) { if (subject == NULL) {
subject = strdup("(No Subject)"); subject = strdup("(No Subject)");
@ -318,9 +323,11 @@ int l_readMessage(lua_State *L) {
if (z != 0) { if (z != 0) {
dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb));
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
body = strdup("No Message"); body = strdup("No Message");
} else if (jmh.Attribute & JAM_MSG_DELETED) { } else if (jmh.Attribute & JAM_MSG_DELETED) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
body = strdup("No Message"); body = strdup("No Message");
} else { } else {
body = (char *)malloc(jmh.TxtLen + 1); body = (char *)malloc(jmh.TxtLen + 1);
@ -328,6 +335,7 @@ int l_readMessage(lua_State *L) {
body[jmh.TxtLen] = '\0'; body[jmh.TxtLen] = '\0';
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
} }
lua_pushstring(L, body); 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) { } else if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NETMAIL_AREA) {
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 0; return 0;
} }
@ -479,7 +488,8 @@ int l_postMessage(lua_State *L) {
sleep(1); sleep(1);
} else { } else {
dolog("Failed to lock msg base!"); dolog("Failed to lock msg base!");
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 0; return 0;
} }
} }
@ -533,6 +543,7 @@ int l_postMessage(lua_State *L) {
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
} }
free(msg); free(msg);

View File

@ -128,6 +128,7 @@ void free_message_headers(struct msg_headers *msghs) {
if (msghs->msgs[i]->replyid != NULL) { if (msghs->msgs[i]->replyid != NULL) {
free(msghs->msgs[i]->replyid); free(msghs->msgs[i]->replyid);
} }
free(msghs->msgs[i]);
} }
if (msghs->msg_count > 0) { if (msghs->msg_count > 0) {
free(msghs->msgs); free(msghs->msgs);
@ -354,9 +355,11 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r
} else { } else {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return NULL; return NULL;
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return msghs; return msghs;
} }
@ -1652,6 +1655,7 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno
if (tolower(c) == 'r') { if (tolower(c) == 'r') {
JAM_CloseMB(jb); 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) { 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)); s_printf(get_string(113));
} else { } else {
@ -1974,6 +1978,7 @@ int read_new_msgs(struct user_record *user, struct msg_headers *msghs) {
all_unread = 1; all_unread = 1;
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
if (all_unread == 0) { if (all_unread == 0) {
k = jlr.HighReadMsg; k = jlr.HighReadMsg;
for (i=0;i<msghs->msg_count;i++) { for (i=0;i<msghs->msg_count;i++) {
@ -2023,6 +2028,7 @@ void read_mail(struct user_record *user) {
all_unread = 1; all_unread = 1;
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
s_printf(get_string(120), msghs->msg_count); s_printf(get_string(120), msghs->msg_count);
s_readstring(buffer, 6); s_readstring(buffer, 6);
@ -2287,6 +2293,7 @@ void post_message(struct user_record *user) {
} }
if (z != 0) { if (z != 0) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return; return;
} }
@ -2311,6 +2318,7 @@ void post_message(struct user_record *user) {
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
free(msg); free(msg);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
} }
free(to); free(to);
free(subject); free(subject);
@ -2349,6 +2357,7 @@ void list_messages(struct user_record *user) {
all_unread = 1; all_unread = 1;
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
s_printf(get_string(125), msghs->msg_count); s_printf(get_string(125), msghs->msg_count);
s_readstring(buffer, 6); s_readstring(buffer, 6);
@ -2577,6 +2586,7 @@ void list_messages(struct user_record *user) {
all_unread = 1; all_unread = 1;
} }
JAM_CloseMB(jb); 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) { if (JAM_ReadMBHeader(jb, &jbh) != 0) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
continue; continue;
} }
if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) {
if (jbh.ActiveMsgs == 0) { if (jbh.ActiveMsgs == 0) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
continue; continue;
} }
if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NETMAIL_AREA) { 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 { } else {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
continue; continue;
} }
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
if (res) { if (res) {
break; break;
} }
@ -3257,6 +3271,7 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) {
if (JAM_ReadMBHeader(jb, &jbh) != 0) { if (JAM_ReadMBHeader(jb, &jbh) != 0) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return; return;
} }
@ -3301,6 +3316,7 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) {
JAM_WriteLastRead(jb, gUser->id, &jlr); JAM_WriteLastRead(jb, gUser->id, &jlr);
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
} }
void msgbase_reset_all_pointers(int readm) { 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) { if (JAM_ReadMBHeader(jb, &jbh) != 0) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 0; return 0;
} }
if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) {
if (jbh.ActiveMsgs == 0) { if (jbh.ActiveMsgs == 0) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 0; return 0;
} }
if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_NETMAIL_AREA) { 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); JAM_CloseMB(jb);
free(jb);
return count; return count;
} }

View File

@ -76,7 +76,7 @@ static int secLevel(void* user, const char* section, const char* name,
} }
int save_user(struct user_record *user) { int save_user(struct user_record *user) {
char buffer[256]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
@ -84,7 +84,7 @@ int save_user(struct user_record *user) {
char *update_sql = "UPDATE users SET password=?, salt=?, firstname=?," 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 ?"; "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); rc = sqlite3_open(buffer, &db);
@ -99,7 +99,7 @@ int save_user(struct user_record *user) {
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
sqlite3_bind_text(res, 1, user->password, -1, 0); 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, 3, user->firstname, -1, 0);
sqlite3_bind_text(res, 4, user->lastname, -1, 0); sqlite3_bind_text(res, 4, user->lastname, -1, 0);
sqlite3_bind_text(res, 5, user->email, -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); rc = sqlite3_step(res);
if (rc != SQLITE_DONE) { if (rc != SQLITE_DONE) {
sqlite3_finalize(res);
dolog("execution failed: %s", sqlite3_errmsg(db)); dolog("execution failed: %s", sqlite3_errmsg(db));
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
return 1; return 1;

View File

@ -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); jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
if (!jb) { if (!jb) {
free(page); free(page);
free_message_headers(mhrs);
return NULL; return NULL;
} }
if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { 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; jlr.HighReadMsg = 0;
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
skip_f = mhrs->msg_count - skip; skip_f = mhrs->msg_count - skip;
skip_t = mhrs->msg_count - skip - 50; skip_t = mhrs->msg_count - skip - 50;
if (skip_t < 0) { 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); z = JAM_ReadMsgHeader(jb, msg - 1, &jmh, &jsp);
if (z != 0) { if (z != 0) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return NULL; return NULL;
} }
if (jmh.Attribute & JAM_MSG_DELETED) { if (jmh.Attribute & JAM_MSG_DELETED) {
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return NULL; return NULL;
} }
@ -390,6 +393,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
free(replyid); free(replyid);
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return NULL; 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_WriteLastRead(jb, user->id, &jlr);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
page = (char *)malloc(4096); page = (char *)malloc(4096);
max_len = 4096; max_len = 4096;
@ -868,11 +873,13 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
sleep(1); sleep(1);
} else { } else {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 0; return 0;
} }
} }
if (z != 0) { if (z != 0) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 0; return 0;
} }
@ -903,6 +910,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
JAM_UnlockMB(jb); JAM_UnlockMB(jb);
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 0; return 0;
} }
body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer)); 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_UnlockMB(jb);
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 0; return 0;
} }
@ -924,6 +933,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference,
JAM_UnlockMB(jb); JAM_UnlockMB(jb);
JAM_DelSubPacket(jsp); JAM_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 0; return 0;
} else { } else {
if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) { 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_DelSubPacket(jsp);
JAM_CloseMB(jb); JAM_CloseMB(jb);
free(jb);
return 1; return 1;
} }
return 0; return 0;