aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/index.cc
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2009-12-01 12:40:13 -0800
committerGravatar Carl Worth <cworth@cworth.org>2009-12-01 12:40:13 -0800
commite5316b320a51915fc1dbdd8724643931cd03327f (patch)
tree39b10f3b8ca51b4658141e083acf56467f9b6b2b /lib/index.cc
parent6320695223e466a285a77fe0d30fff0ff5e89172 (diff)
lib/index: Fix memory leak for email addresses without names.
We carefully noted the fact that we had locally allocated the string here, but then we neglected to free it. Switch to talloc instead which makes it easier to get the behavior we want. It's simpler since we can just call talloc_free unconditionally, without having to track the state of whether we allocated the storage for name or not.
Diffstat (limited to 'lib/index.cc')
-rw-r--r--lib/index.cc10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/index.cc b/lib/index.cc
index 80df64bf..125fa6c9 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -31,7 +31,7 @@ _index_address_mailbox (notmuch_message_t *message,
{
InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
const char *name, *addr;
- int own_name = 0;
+ void *local = talloc_new (NULL);
name = internet_address_get_name (address);
addr = internet_address_mailbox_get_addr (mailbox);
@@ -42,16 +42,16 @@ _index_address_mailbox (notmuch_message_t *message,
const char *at;
at = strchr (addr, '@');
- if (at) {
- name = strndup (addr, at - addr);
- own_name = 1;
- }
+ if (at)
+ name = talloc_strndup (local, addr, at - addr);
}
if (name)
_notmuch_message_gen_terms (message, prefix_name, name);
if (addr)
_notmuch_message_gen_terms (message, prefix_name, addr);
+
+ talloc_free (local);
}
static void