[PATCH v3] Release memory allocated by internet_address_list_parse_string()

Tomi Ollila tomi.ollila at iki.fi
Sat Dec 10 02:18:54 PST 2011


g_object_unref() releases the memory of the InternetAddressList object
returned by internet_address_list_parse_string() -- when last (only)
reference is released, internet_address_list_finalize() will do cleanup.
---

hmm, have to agree amdragon's "suggested alternative" is more robust 
(in maintainability point of view) than the one I took previously.

The 3 other alternatives are not common in notmuch code and therefore dropped:
1) use multiple goto labels to jump in
2) use deeply nested if blocks
3) the ultimate solution: do { .. } while (0) blocks and break;s >;)

When reviewing, see also gmime-2.4.25/gmime/internet-address.c (or older)
I tested this patch by entering:  notmuch show --format=mbox '*' | wc

 notmuch-show.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 603992a..873a7c4 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -255,7 +255,9 @@ _extract_email_address (const void *ctx, const char *from)
     email = talloc_strdup (ctx, email);
 
   DONE:
-    /* XXX: How to free addresses here? */
+    if (addresses)
+	g_object_unref (addresses);
+
     return email;
    }
 
-- 
1.7.7.3


More information about the notmuch mailing list