Re: [PATCH v2] Free the results of scandir()
authorJani Nikula <jani@nikula.org>
Tue, 7 Feb 2012 08:26:16 +0000 (08:26 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:14 +0000 (09:44 -0800)
62/112f4308d5ae5e802f2d746ccf62a0951a3b0b [new file with mode: 0644]

diff --git a/62/112f4308d5ae5e802f2d746ccf62a0951a3b0b b/62/112f4308d5ae5e802f2d746ccf62a0951a3b0b
new file mode 100644 (file)
index 0000000..4489607
--- /dev/null
@@ -0,0 +1,126 @@
+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 EBA08431FAF\r
+       for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 00:26:26 -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 6WJduB45Z3rC for <notmuch@notmuchmail.org>;\r
+       Tue,  7 Feb 2012 00:26:26 -0800 (PST)\r
+Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com\r
+       [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 3168D431FAE\r
+       for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 00:26:26 -0800 (PST)\r
+Received: by qcsd17 with SMTP id d17so4513675qcs.26\r
+       for <notmuch@notmuchmail.org>; Tue, 07 Feb 2012 00:26:24 -0800 (PST)\r
+Received: by 10.229.134.210 with SMTP id k18mr8559725qct.136.1328603180092;\r
+       Tue, 07 Feb 2012 00:26:20 -0800 (PST)\r
+Received: from localhost (nikula.org. [92.243.24.172])\r
+       by mx.google.com with ESMTPS id j17sm19311897qaj.9.2012.02.07.00.26.18\r
+       (version=SSLv3 cipher=OTHER); Tue, 07 Feb 2012 00:26:19 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Ethan Glasser-Camp <glasse@cs.rpi.edu>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2] Free the results of scandir()\r
+In-Reply-To: <1328597405-6437-1-git-send-email-glasse@cs.rpi.edu>\r
+References: <1328597405-6437-1-git-send-email-glasse@cs.rpi.edu>\r
+User-Agent: Notmuch/0.11.1+158~g413777a (http://notmuchmail.org) Emacs/23.1.1\r
+       (i686-pc-linux-gnu)\r
+Date: Tue, 07 Feb 2012 08:26:16 +0000\r
+Message-ID: <87sjinqcbb.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Cc: Petter Reinholdtsen <pere@hungry.com>,\r
+       Ethan Glasser-Camp <ethan@betacantrips.com>\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: Tue, 07 Feb 2012 08:26:27 -0000\r
+\r
+On Tue,  7 Feb 2012 01:50:05 -0500, Ethan Glasser-Camp <glasse@cs.rpi.edu> wrote:\r
+> From: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+> \r
+> scandir() returns "strings allocated via malloc(3)" which are then\r
+> "collected in array namelist which is allocated via\r
+> malloc(3)". Currently we just free the array namelist. Instead, free\r
+> all the entries of namelist, and then free namelist.\r
+> \r
+> entry only points to elements of namelist, so we don't free it\r
+> separately.\r
+\r
+Looks good. Thanks, Ethan.\r
+\r
+David, I'm not sure if this is worth a bugfix release on its own, but\r
+definitely worth including if something else comes up.\r
+\r
+id:"2flfwhht87d.fsf@diskless.uio.no" is a report about potential memory\r
+leak in notmuch new from a few months back. CC Petter, the reporter.\r
+\r
+> ---\r
+> \r
+> Fixes the other use of scandir in count_files. Thanks, Jani.\r
+> \r
+>  notmuch-new.c |   16 ++++++++++------\r
+>  1 files changed, 10 insertions(+), 6 deletions(-)\r
+> \r
+> diff --git a/notmuch-new.c b/notmuch-new.c\r
+> index a569a54..e62560b 100644\r
+> --- a/notmuch-new.c\r
+> +++ b/notmuch-new.c\r
+> @@ -559,12 +559,14 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+>    DONE:\r
+>      if (next)\r
+>      talloc_free (next);\r
+> -    if (entry)\r
+> -    free (entry);\r
+>      if (dir)\r
+>      closedir (dir);\r
+> -    if (fs_entries)\r
+> +    if (fs_entries){\r
+> +    for (i = 0; i < num_fs_entries; i++){\r
+> +        free (fs_entries[i]);\r
+> +    }\r
+>      free (fs_entries);\r
+> +    }\r
+>      if (db_subdirs)\r
+>      notmuch_filenames_destroy (db_subdirs);\r
+>      if (db_files)\r
+> @@ -704,10 +706,12 @@ count_files (const char *path, int *count)\r
+>      }\r
+>  \r
+>    DONE:\r
+> -    if (entry)\r
+> -    free (entry);\r
+> -    if (fs_entries)\r
+> +    if (fs_entries){\r
+> +    for (i = 0; i < num_fs_entries; i++){\r
+> +        free (fs_entries[i]);\r
+> +    }\r
+>          free (fs_entries);\r
+> +    }\r
+>  }\r
+>  \r
+>  static void\r
+> -- \r
+> 1.7.5.4\r
+> \r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r