--- /dev/null
+Return-Path: <Vladimir.Marek@oracle.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id B3773431FB6\r
+ for <notmuch@notmuchmail.org>; Thu, 2 May 2013 07:32:07 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.299\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.299 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3, UNPARSEABLE_RELAY=0.001]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id OTP91JQCGroS for <notmuch@notmuchmail.org>;\r
+ Thu, 2 May 2013 07:32:02 -0700 (PDT)\r
+Received: from userp1040.oracle.com (userp1040.oracle.com [156.151.31.81])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id D61C5431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 2 May 2013 07:32:02 -0700 (PDT)\r
+Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94])\r
+ by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with\r
+ ESMTP id r42EW05q011542\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);\r
+ Thu, 2 May 2013 14:32:01 GMT\r
+Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230])\r
+ by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+ r42EVwdM004135\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL);\r
+ Thu, 2 May 2013 14:32:00 GMT\r
+Received: from abhmt119.oracle.com (abhmt119.oracle.com [141.146.116.71])\r
+ by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+ r42EVwBS010040; Thu, 2 May 2013 14:31:58 GMT\r
+Received: from tbd.cz.oracle.com (/10.163.101.124)\r
+ by default (Oracle Beehive Gateway v4.0)\r
+ with ESMTP ; Thu, 02 May 2013 07:31:58 -0700\r
+From: Vladimir.Marek@oracle.com\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] lib/message.cc: stale pointer bug (v3)\r
+Date: Thu, 2 May 2013 16:31:42 +0200\r
+Message-Id: <1367505102-12860-1-git-send-email-Vladimir.Marek@oracle.com>\r
+X-Mailer: git-send-email 1.7.9.2\r
+X-Source-IP: ucsinet22.oracle.com [156.151.31.94]\r
+Cc: Vladimir Marek <vlmarek@volny.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 02 May 2013 14:32:07 -0000\r
+\r
+From: Vladimir Marek <vlmarek@volny.cz>\r
+\r
+Xapian::TermIterator::operator* returns std::string which is destroyed\r
+as soon as (*i).c_str() finishes. The remembered pointer 'term' then\r
+references invalid memory.\r
+\r
+Signed-off-by: Vladimir Marek <vlmarek@volny.cz>\r
+---\r
+ lib/message.cc | 10 +++++-----\r
+ 1 file changed, 5 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 8720c1b..c4261e6 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -266,18 +266,18 @@ _notmuch_message_get_term (notmuch_message_t *message,\r
+ const char *prefix)\r
+ {\r
+ int prefix_len = strlen (prefix);\r
+- const char *term = NULL;\r
+ char *value;\r
+ \r
+ i.skip_to (prefix);\r
+ \r
+- if (i != end)\r
+- term = (*i).c_str ();\r
++ if (i == end)\r
++ return NULL;\r
+ \r
+- if (!term || strncmp (term, prefix, prefix_len))\r
++ std::string term = *i;\r
++ if (strncmp (term.c_str(), prefix, prefix_len))\r
+ return NULL;\r
+ \r
+- value = talloc_strdup (message, term + prefix_len);\r
++ value = talloc_strdup (message, term.c_str() + prefix_len);\r
+ \r
+ #if DEBUG_DATABASE_SANITY\r
+ i++;\r
+-- \r
+1.7.9.2\r
+\r