[balsa] mailbox-local: Do not leak LibBalsaMessage
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] mailbox-local: Do not leak LibBalsaMessage
- Date: Sat, 16 Feb 2019 22:03:08 +0000 (UTC)
commit b6515d6bca4b0d30cd30629c9135fce27b563d00
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Sat Feb 16 17:01:57 2019 -0500
mailbox-local: Do not leak LibBalsaMessage
* libbalsa/mailbox_local.c (lbml_message_pool_take_message): new
name for 'lbml_add_message_to_pool', emphasizing that it takes
over the reference count;
(lbm_local_get_message_with_msg_info): use the new name;
(libbalsa_mailbox_local_get_message): always return a reference
to the LibBalsaMessage.
ChangeLog | 11 +++++++++++
libbalsa/mailbox_local.c | 27 +++++++++++----------------
2 files changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6a9feda19..a74d12ec9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-02-16 Peter Bloomfield <pbloomfield bellsouth net>
+
+ mailbox-local: Do not leak LibBalsaMessage
+
+ * libbalsa/mailbox_local.c (lbml_message_pool_take_message): new
+ name for 'lbml_add_message_to_pool', emphasizing that it takes
+ over the reference count;
+ (lbm_local_get_message_with_msg_info): use the new name;
+ (libbalsa_mailbox_local_get_message): always return a reference
+ to the LibBalsaMessage.
+
2019-02-16 Peter Bloomfield <pbloomfield bellsouth net>
imap-mbox-handle: Do not leak a GNode tree
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 84cdc9e2c..d2a6bad4f 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -278,26 +278,23 @@ libbalsa_mailbox_local_remove_files(LibBalsaMailboxLocal * local)
*/
static void
-lbml_add_message_to_pool(LibBalsaMailboxLocal * local,
- LibBalsaMessage * message)
+lbml_message_pool_take_message(LibBalsaMailboxLocal * local,
+ LibBalsaMessage * message)
{
LibBalsaMailboxLocalPool *item, *oldest;
++local->pool_seqno;
for (item = oldest = &local->message_pool[0];
- item < &local->message_pool[LBML_POOL_SIZE]; item++) {
- if (item->message == message) {
- item->pool_seqno = local->pool_seqno;
- return;
- }
+ item < &local->message_pool[LBML_POOL_SIZE];
+ item++) {
if (item->pool_seqno < oldest->pool_seqno)
oldest = item;
}
- if (oldest->message)
+ if (oldest->message != NULL)
g_object_unref(oldest->message);
- oldest->message = g_object_ref(message);
+ oldest->message = message; /* we take over the reference count */
oldest->pool_seqno = local->pool_seqno;
}
@@ -311,13 +308,13 @@ lbm_local_get_message_with_msg_info(LibBalsaMailboxLocal * local,
msg_info->message = message = libbalsa_message_new();
g_object_add_weak_pointer(G_OBJECT(message),
- (gpointer) & msg_info->message);
+ (gpointer *) & msg_info->message);
message->flags = msg_info->flags & LIBBALSA_MESSAGE_FLAGS_REAL;
message->mailbox = LIBBALSA_MAILBOX(local);
message->msgno = msgno;
libbalsa_message_load_envelope(message);
- lbml_add_message_to_pool(local, message);
+ lbml_message_pool_take_message(local, message);
}
static gboolean message_match_real(LibBalsaMailbox * mailbox, guint msgno,
@@ -804,12 +801,10 @@ libbalsa_mailbox_local_get_message(LibBalsaMailbox * mailbox, guint msgno)
LibBalsaMailboxLocalMessageInfo *msg_info =
LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->get_info(local, msgno);
- if (msg_info->message)
- return g_object_ref(msg_info->message);
-
- lbm_local_get_message_with_msg_info(local, msgno, msg_info);
+ if (msg_info->message == NULL)
+ lbm_local_get_message_with_msg_info(local, msgno, msg_info);
- return msg_info->message;
+ return g_object_ref(msg_info->message);
}
/* Search iters. We do not use the fallback version because it does
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]