AmendHub

jcs

/

subtext

/

amendments

/

234

mail: Fix a memory leak, pass malloc notes to bile


jcs made amendment 234 2 months ago
--- mail.c Sun Jul 31 21:28:31 2022 +++ mail.c Mon Aug 1 16:10:36 2022 @@ -420,10 +420,11 @@ mail_list(struct session *s, size_t nmail_ids, unsigne if (size == 0) break; bile_unmarshall_object(db->bile, mail_object_fields, - nitems(mail_object_fields), data, size, &msg, sizeof(msg), true); + nitems(mail_object_fields), data, size, &msg, sizeof(msg), true, + "mail_list"); xfree(&data); - user = user_find_username(msg.sender_user_id); + user = user_username(msg.sender_user_id); strftime(time, sizeof(time), "%b %d", localtime(&msg.time)); session_printf(s, "%s%ld %c %s %- 10s {{#}}%- 40s%s\r\n", @@ -472,11 +473,12 @@ mail_read(struct session *s, unsigned long id, short i } bile_unmarshall_object(db->bile, mail_object_fields, - nitems(mail_object_fields), data, size, &msg, sizeof(msg), true); + nitems(mail_object_fields), data, size, &msg, sizeof(msg), true, + "mail_read"); xfree(&data); - sender = user_find_username(msg.sender_user_id); - recipient = user_find_username(msg.recipient_user_id); + sender = user_username(msg.sender_user_id); + recipient = user_username(msg.recipient_user_id); strftime(time, sizeof(time), "%Y-%m-%d %H:%M:%S", localtime(&msg.time)); @@ -588,7 +590,7 @@ mail_save(struct session *s, struct mail_message *msg) msg->id = bile_next_id(db->bile, DB_MESSAGE_RTYPE); ret = bile_marshall_object(db->bile, mail_object_fields, - nitems(mail_object_fields), msg, &data, &size); + nitems(mail_object_fields), msg, &data, &size, "mail_save"); if (ret != 0 || size == 0) { warn("mail_save: failed to marshall object"); return -1; @@ -635,7 +637,9 @@ mail_find_ids_for_user(struct user *user, size_t *nmai if (only_unread) { size = bile_read_alloc(db->bile, DB_MESSAGE_RTYPE, id, &data); bile_unmarshall_object(db->bile, mail_object_fields, - nmail_object_fields, data, size, &msg, sizeof(msg), false); + nmail_object_fields, data, size, &msg, sizeof(msg), false, + "mail_find_ids_for_user"); + xfree(&data); read = msg.read; if (read) continue;