lib/message.cc: stale pointer bug (v3)

Xapian::TermIterator::operator* returns std::string which is destroyed
as soon as (*i).c_str() finishes. The remembered pointer 'term' then
references invalid memory.

Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
This commit is contained in:
Vladimir Marek 2013-05-02 16:31:42 +02:00 committed by David Bremner
parent 8bee3c417c
commit 51b073c6f2

View file

@ -266,18 +266,18 @@ _notmuch_message_get_term (notmuch_message_t *message,
const char *prefix)
{
int prefix_len = strlen (prefix);
const char *term = NULL;
char *value;
i.skip_to (prefix);
if (i != end)
term = (*i).c_str ();
if (!term || strncmp (term, prefix, prefix_len))
if (i == end)
return NULL;
value = talloc_strdup (message, term + prefix_len);
std::string term = *i;
if (strncmp (term.c_str(), prefix, prefix_len))
return NULL;
value = talloc_strdup (message, term.c_str() + prefix_len);
#if DEBUG_DATABASE_SANITY
i++;