--- /dev/null
+Return-Path: <bremner@tethera.net>\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 D56EB429E36\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 12:16:58 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\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 Sf6cFER3FIpC for <notmuch@notmuchmail.org>;\r
+ Sun, 16 Dec 2012 12:16:58 -0800 (PST)\r
+Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
+ (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 027DB431FD2\r
+ for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 12:16:57 -0800 (PST)\r
+Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net\r
+ ([142.167.90.129] helo=zancas.localnet)\r
+ by tesseract.cs.unb.ca with esmtpsa\r
+ (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1TkKdt-0007td-94; Sun, 16 Dec 2012 16:16:57 -0400\r
+Received: from bremner by zancas.localnet with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1TkKdn-00050j-Q9; Sun, 16 Dec 2012 16:16:51 -0400\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] notmuch-restore: allocate a temporary talloc context for\r
+ each line parsed.\r
+Date: Sun, 16 Dec 2012 16:16:37 -0400\r
+Message-Id: <1355688997-19164-4-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1355688997-19164-1-git-send-email-david@tethera.net>\r
+References: <1355688997-19164-1-git-send-email-david@tethera.net>\r
+X-Spam_bar: -\r
+Cc: David Bremner <bremner@debian.org>\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: Sun, 16 Dec 2012 20:16:59 -0000\r
+\r
+From: David Bremner <bremner@debian.org>\r
+\r
+This lets the high level code in notmuch restore be ignorant about\r
+what the lower level code is doing as far as allocating memory.\r
+---\r
+ notmuch-restore.c | 12 ++++++++++--\r
+ 1 file changed, 10 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index 4b76d83..52e7ecb 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -122,6 +122,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+ char *input_file_name = NULL;\r
+ FILE *input = stdin;\r
+ char *line = NULL;\r
++ void *line_ctx = NULL;\r
+ size_t line_size;\r
+ ssize_t line_len;\r
+ \r
+@@ -205,10 +206,11 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+ do {\r
+ char *query_string;\r
+ \r
++ line_ctx = talloc_new (ctx);\r
+ if (input_format == DUMP_FORMAT_SUP) {\r
+- ret = parse_sup_line (ctx, line, &query_string, tag_ops);\r
++ ret = parse_sup_line (line_ctx, line, &query_string, tag_ops);\r
+ } else {\r
+- ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS,\r
++ ret = parse_tag_line (line_ctx, line, TAG_FLAG_BE_GENEROUS,\r
+ &query_string, tag_ops);\r
+ \r
+ if (ret == 0) {\r
+@@ -238,8 +240,14 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+ break;\r
+ }\r
+ \r
++ talloc_free (line_ctx);\r
++ /* setting to NULL is important to avoid a double free */\r
++ line_ctx = NULL;\r
+ } while ((line_len = getline (&line, &line_size, input)) != -1);\r
+ \r
++ if (line_ctx != NULL)\r
++ talloc_free (line_ctx);\r
++\r
+ if (input_format == DUMP_FORMAT_SUP)\r
+ regfree (®ex);\r
+ \r
+-- \r
+1.7.10.4\r
+\r