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