summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Pamment <apamment@yandex.com>2019-01-04 09:54:47 +1000
committerAndrew Pamment <apamment@yandex.com>2019-01-04 09:54:47 +1000
commit59a471e7e8e8500667b1f79d658643d7607dd896 (patch)
treed8aaaae7f6cad7a2278eedf6c8c82ac2a86bdcd8
parent027a912a4a4421e8c839dfe55de9f56651e4facc (diff)
Fix some memory leaks and off by one new mail scan
-rw-r--r--src/blog.c9
-rw-r--r--src/mail_menu.c25
2 files changed, 16 insertions, 18 deletions
diff --git a/src/blog.c b/src/blog.c
index 1d9b58e..03c2a78 100644
--- a/src/blog.c
+++ b/src/blog.c
@@ -151,7 +151,16 @@ void blog_display() {
lines = 0;
}
}
+
+ for (size_t i = 0; i < ptr_vector_len(&entries); i++) {
+ struct blog_entry_t *entry = ptr_vector_get(&entries, i);
+ free(entry->subject);
+ free(entry->author);
+ free(entry->body);
+ }
+
ptr_vector_apply(&entries, free);
+
destroy_ptr_vector(&entries);
s_printf(get_string(6));
diff --git a/src/mail_menu.c b/src/mail_menu.c
index 718756a..b7236d1 100644
--- a/src/mail_menu.c
+++ b/src/mail_menu.c
@@ -2675,7 +2675,7 @@ int count_msgs_above_msgno(struct msg_headers *msghs, int highmsgno) {
int highmsg = 0;
for (i = msghs->msg_count - 1; i >= 0; i--) {
- if (msghs->msgs[i]->msg_no < highmsgno) break;
+ if (msghs->msgs[i]->msg_no <= highmsgno) break;
highmsg++;
}
return highmsg;
@@ -2748,16 +2748,12 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) {
high_read = get_message_highread(mb, user->id);
-
+
+ close_message_base(mb);
+
if (high_read < get_message_number(msghs, msghs->msg_count - 1)) {
if (ma->type == TYPE_NETMAIL_AREA) {
- unread_count = 0;
- for (k = msghs->msg_count - 1; k >= 0; k--) {
- if (msghs->msgs[k]->msg_no < high_read) {
- break;
- }
- unread_count++;
- }
+ unread_count = count_msgs_above_msgno(msghs, high_read);
if (unread_count > 0) {
if (oldscan) {
s_printf(get_string(141), j, ma->name, unread_count);
@@ -2799,14 +2795,7 @@ void do_mail_scan(struct user_record *user, int oldscan, int personal) {
lines = 0;
}
} else {
- unread_count = 0;
-
- for (k = msghs->msg_count - 1; k >= 0; k--) {
- if (get_message_number(msghs, k) < high_read) {
- break;
- }
- unread_count++;
- }
+ unread_count = count_msgs_above_msgno(msghs, high_read);
if (unread_count > 0) {
s_printf("\e[2J\e[1;1H");
s_printf(get_string(277), i, mc->name);
@@ -3078,7 +3067,7 @@ int new_messages(struct user_record *user, int conference, int area) {
if (msghs != NULL) {
if (msghs->msg_count > 0) {
if (get_message_number(msghs, msghs->msg_count - 1) > high_read) {
- count = get_message_number(msghs, msghs->msg_count - 1) - high_read;
+ count = count_msgs_above_msgno(msghs, high_read);
}
}
free_message_headers(msghs);