lib/index: Fix memory leak for email addresses without names.
[notmuch] / lib / index.cc
index 80df64bfb73a3edbf2ff9819e99c473c3d41f81b..125fa6c94f2b6612f6aac3e36dfe518753eaddaf 100644 (file)
@@ -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