From 51b073c6f27f4439b2d003df1be1177365e555fe Mon Sep 17 00:00:00 2001 From: Vladimir Marek Date: Thu, 2 May 2013 16:31:42 +0200 Subject: [PATCH] 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 --- lib/message.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 8720c1b5..c4261e61 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -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 (i == end) + return NULL; - if (!term || strncmp (term, prefix, prefix_len)) + std::string term = *i; + if (strncmp (term.c_str(), prefix, prefix_len)) return NULL; - value = talloc_strdup (message, term + prefix_len); + value = talloc_strdup (message, term.c_str() + prefix_len); #if DEBUG_DATABASE_SANITY i++; -- 2.26.2