Re: [PATCH 3/3] notmuch-restore: allocate a temporary talloc context for each line...
authorJani Nikula <jani@nikula.org>
Sun, 16 Dec 2012 22:41:12 +0000 (00:41 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:27 +0000 (09:52 -0800)
b1/966830176e31a8446e56cc5991d9c39fb4cf91 [new file with mode: 0644]

diff --git a/b1/966830176e31a8446e56cc5991d9c39fb4cf91 b/b1/966830176e31a8446e56cc5991d9c39fb4cf91
new file mode 100644 (file)
index 0000000..d40d9e0
--- /dev/null
@@ -0,0 +1,149 @@
+Return-Path: <jani@nikula.org>\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 2E138431FAF\r
+       for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 14:41:18 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 JzGigM5Zzgo6 for <notmuch@notmuchmail.org>;\r
+       Sun, 16 Dec 2012 14:41:17 -0800 (PST)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+       [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 40723431FAE\r
+       for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 14:41:17 -0800 (PST)\r
+Received: by mail-lb0-f181.google.com with SMTP id ge1so4083048lbb.26\r
+       for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 14:41:15 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
+       :message-id:mime-version:content-type:x-gm-message-state;\r
+       bh=cqaFOzs62Te1J0RpDPkl6NQStKZTCgly1GYCqm/9AMQ=;\r
+       b=HJETT2P+6f+L0VKblXINRJyn7Yrett/KjUYEYZUZ0qp/Npx8wn/B4l8CnQsHD7PySP\r
+       bKw/GhEyIo/Uyzi38eRaESPPW58FgixubO/ViPufskPNjRJY64OoWvtKuFtq1KrsUFIB\r
+       w3kSXDRuBGXQ3A7F71EHMQbZMFkkl9Lhc8TjJdLqUhGq3hDzcPsUiN7cQq5ti4K3EC3C\r
+       yMXoOBTwGEmOCzcmDo+w3gODVfToIq5RwQAlLRwR/Aqa4QOP/TDa5YvG6D8rcNNkt7TD\r
+       KY4YI9KPfAqfAwHZHMmp37iii4EvEXCVFMmgszJoRNUUDz9EyoZWaDySgUtOKK0WzLRg\r
+       oeiw==\r
+Received: by 10.112.83.100 with SMTP id p4mr5048275lby.96.1355697675705;\r
+       Sun, 16 Dec 2012 14:41:15 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id ne2sm4136684lab.10.2012.12.16.14.41.13\r
+       (version=SSLv3 cipher=OTHER); Sun, 16 Dec 2012 14:41:14 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: david@tethera.net, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 3/3] notmuch-restore: allocate a temporary talloc context\r
+       for each line parsed.\r
+In-Reply-To: <1355688997-19164-4-git-send-email-david@tethera.net>\r
+References: <1355688997-19164-1-git-send-email-david@tethera.net>\r
+       <1355688997-19164-4-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1\r
+       (i686-pc-linux-gnu)\r
+Date: Mon, 17 Dec 2012 00:41:12 +0200\r
+Message-ID: <87ip81pqlz.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQmY0f2V6oBOtXX0PPWxxSqtiNu9/NXE8l70UadLGl939ySkZwfwbeIzsj/OC9XZ7gYAux8Z\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 22:41:18 -0000\r
+\r
+On Sun, 16 Dec 2012, david@tethera.net wrote:\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
+This patch only works on top of the batch tagging series, because\r
+there's still one continue statement in the "id:" prefix check. But you\r
+could make it work for both, *and* keep the slightly more intuitive ret\r
+checking order if you did (yes, the slightly counter-intuitive):\r
+\r
+       if (line_ctxt != NULL)\r
+         talloc_free (line_ctx);\r
+\r
+right here, and...\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
+\r
+...removed the above lines here.\r
+\r
+Otherwise I think you'll need a temporary goto until the batch tagging\r
+series. (I'm fine with that too.)\r
+\r
+Overall the series LGTM, and I like how this dodges the query_string\r
+alloc/free problem altogether.\r
+\r
+BR,\r
+Jani.\r
+\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 (&regex);\r
+>  \r
+> -- \r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r