[PATCH 1/3] tag-utils: use the tag_opt_list_t as talloc context, if possible.
authordavid <david@tethera.net>
Sun, 16 Dec 2012 20:16:35 +0000 (16:16 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:24 +0000 (09:52 -0800)
35/48961a53f864902b8380dd35df611019fac084 [new file with mode: 0644]

diff --git a/35/48961a53f864902b8380dd35df611019fac084 b/35/48961a53f864902b8380dd35df611019fac084
new file mode 100644 (file)
index 0000000..7c38c45
--- /dev/null
@@ -0,0 +1,139 @@
+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 2A56A431FD2\r
+       for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 12:16:59 -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 04kUdoSJ2jec 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 F3C9D431FC4\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-0007tb-0F; 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-00050b-I9; Sun, 16 Dec 2012 16:16:51 -0400\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/3] tag-utils: use the tag_opt_list_t as talloc context,\r
+       if possible.\r
+Date: Sun, 16 Dec 2012 16:16:35 -0400\r
+Message-Id: <1355688997-19164-2-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 code is no less correct than the previous version, since it does\r
+not make sense for the array to live longer than the wrapping struct.\r
+\r
+By not relying on the context passed into tag_parse_line, we can allow\r
+tag_op_list_t structures to live longer than that context.\r
+---\r
+ notmuch-restore.c |    2 +-\r
+ tag-util.c        |    9 ++++-----\r
+ tag-util.h        |    3 +--\r
+ 3 files changed, 6 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index 40596a8..ae0ef45 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -102,7 +102,7 @@ parse_sup_line (void *ctx, char *line,\r
+           tok_len++;\r
+       }\r
\r
+-      if (tag_op_list_append (ctx, tag_ops, tok, FALSE))\r
++      if (tag_op_list_append (tag_ops, tok, FALSE))\r
+           return -1;\r
+     }\r
\r
+diff --git a/tag-util.c b/tag-util.c\r
+index eab482f..705b7ba 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -109,7 +109,7 @@ parse_tag_line (void *ctx, char *line,\r
+           goto DONE;\r
+       }\r
\r
+-      if (tag_op_list_append (ctx, tag_ops, tag, remove)) {\r
++      if (tag_op_list_append (tag_ops, tag, remove)) {\r
+           ret = line_error (TAG_PARSE_OUT_OF_MEMORY, line_for_error,\r
+                             "aborting");\r
+           goto DONE;\r
+@@ -294,7 +294,7 @@ tag_op_list_create (void *ctx)\r
+     list->size = TAG_OP_LIST_INITIAL_SIZE;\r
+     list->count = 0;\r
\r
+-    list->ops = talloc_array (ctx, tag_operation_t, list->size);\r
++    list->ops = talloc_array (list, tag_operation_t, list->size);\r
+     if (list->ops == NULL)\r
+       return NULL;\r
\r
+@@ -303,8 +303,7 @@ tag_op_list_create (void *ctx)\r
\r
\r
+ int\r
+-tag_op_list_append (void *ctx,\r
+-                  tag_op_list_t *list,\r
++tag_op_list_append (tag_op_list_t *list,\r
+                   const char *tag,\r
+                   notmuch_bool_t remove)\r
+ {\r
+@@ -314,7 +313,7 @@ tag_op_list_append (void *ctx,\r
\r
+     if (list->count == list->size) {\r
+       list->size *= 2;\r
+-      list->ops = talloc_realloc (ctx, list->ops, tag_operation_t,\r
++      list->ops = talloc_realloc (list, list->ops, tag_operation_t,\r
+                                   list->size);\r
+       if (list->ops == NULL) {\r
+           fprintf (stderr, "Out of memory.\n");\r
+diff --git a/tag-util.h b/tag-util.h\r
+index 99b0fa0..c07bfde 100644\r
+--- a/tag-util.h\r
++++ b/tag-util.h\r
+@@ -87,8 +87,7 @@ tag_op_list_create (void *ctx);\r
+  */\r
\r
+ int\r
+-tag_op_list_append (void *ctx,\r
+-                  tag_op_list_t *list,\r
++tag_op_list_append (tag_op_list_t *list,\r
+                   const char *tag,\r
+                   notmuch_bool_t remove);\r
\r
+-- \r
+1.7.10.4\r
+\r