mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-29 06:04:11 +01:00
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.
This commit is contained in:
parent
6320695223
commit
e5316b320a
1 changed files with 5 additions and 5 deletions
10
lib/index.cc
10
lib/index.cc
|
@ -31,7 +31,7 @@ _index_address_mailbox (notmuch_message_t *message,
|
||||||
{
|
{
|
||||||
InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
|
InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
|
||||||
const char *name, *addr;
|
const char *name, *addr;
|
||||||
int own_name = 0;
|
void *local = talloc_new (NULL);
|
||||||
|
|
||||||
name = internet_address_get_name (address);
|
name = internet_address_get_name (address);
|
||||||
addr = internet_address_mailbox_get_addr (mailbox);
|
addr = internet_address_mailbox_get_addr (mailbox);
|
||||||
|
@ -42,16 +42,16 @@ _index_address_mailbox (notmuch_message_t *message,
|
||||||
const char *at;
|
const char *at;
|
||||||
|
|
||||||
at = strchr (addr, '@');
|
at = strchr (addr, '@');
|
||||||
if (at) {
|
if (at)
|
||||||
name = strndup (addr, at - addr);
|
name = talloc_strndup (local, addr, at - addr);
|
||||||
own_name = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
_notmuch_message_gen_terms (message, prefix_name, name);
|
_notmuch_message_gen_terms (message, prefix_name, name);
|
||||||
if (addr)
|
if (addr)
|
||||||
_notmuch_message_gen_terms (message, prefix_name, addr);
|
_notmuch_message_gen_terms (message, prefix_name, addr);
|
||||||
|
|
||||||
|
talloc_free (local);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue