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 D5B5B431FB6 for ; Tue, 7 Feb 2012 00:34:27 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 6wZRtckBnmTc for ; Tue, 7 Feb 2012 00:34:27 -0800 (PST) Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id C199C431FAE for ; Tue, 7 Feb 2012 00:34:26 -0800 (PST) Received: by bke11 with SMTP id 11so6228204bke.26 for ; Tue, 07 Feb 2012 00:34:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; bh=XWvVEsew+3MQRJA+TjhueiSyWOV0QNnhiVO1YF/QOGc=; b=H5/D33/rgpGEWikmvIPOtrHJxnjvO8/ii/nDK5g1RGK/4MeXFnCR38amQRHjVGunSP D8O8yEOfJf9qD2qj4DIADwsEQIF0pIw8BrZEC65cUGxoZFt143lw9DjMzZVZjdv/urYI rP+YMiKPFNNA9E3NxKhqfC5ysV/h3/zP3vA8Y= Received: by 10.205.133.196 with SMTP id hz4mr3033097bkc.71.1328603664719; Tue, 07 Feb 2012 00:34:24 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id bw9sm53347216bkb.8.2012.02.07.00.34.23 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Feb 2012 00:34:23 -0800 (PST) From: Dmitry Kurochkin 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+139~gd9b7cab (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Tue, 07 Feb 2012 12:33:08 +0400 Message-ID: <871uq7yrej.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: 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:34:28 -0000 Hi Ethan. 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. > --- > > Fixes the other use of scandir in count_files. Thanks, Jani. > Few style comments below. Otherwise looks good. > 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){ Please add a space before '{'. > + for (i = 0; i < num_fs_entries; i++){ > + free (fs_entries[i]); > + } Please remove "{}" around one line block. > 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]); > + } Same two comments here. Regards, Dmitry > free (fs_entries); > + } > } > > static void > -- > 1.7.5.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch