From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 0C196431FAF for ; Mon, 6 Feb 2012 14:21:28 -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 aIHGFXBTVUFq for ; Mon, 6 Feb 2012 14:21:27 -0800 (PST) Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 275BE431FAE for ; Mon, 6 Feb 2012 14:21:27 -0800 (PST) Received: by lahd3 with SMTP id d3so3964852lah.26 for ; Mon, 06 Feb 2012 14:21:25 -0800 (PST) Received: by 10.152.146.163 with SMTP id td3mr109516lab.31.1328566885702; Mon, 06 Feb 2012 14:21:25 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi. [84.248.80.253]) by mx.google.com with ESMTPS id j4sm14067691lbf.6.2012.02.06.14.21.23 (version=SSLv3 cipher=OTHER); Mon, 06 Feb 2012 14:21:24 -0800 (PST) From: Jani Nikula To: Ethan Glasser-Camp , notmuch@notmuchmail.org Subject: Re: [PATCH] Free the results of scandir() In-Reply-To: <1328565769-29414-1-git-send-email-glasse@cs.rpi.edu> References: <1328565769-29414-1-git-send-email-glasse@cs.rpi.edu> User-Agent: Notmuch/0.11+139~g4340989 (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) Date: Tue, 07 Feb 2012 00:21:21 +0200 Message-ID: <878vkfppr2.fsf@nikula.org> 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: Mon, 06 Feb 2012 22:21:28 -0000 On Mon, 6 Feb 2012 17:02:49 -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. > --- > > This should fix a minor memory leak in notmuch-new. Please confirm I'm > reading the manpage correctly ;) It looks right, good catch! Please do also fix the other scandir() usage in count_files(). BR, Jani. > > notmuch-new.c | 8 +++++--- > 1 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/notmuch-new.c b/notmuch-new.c > index a569a54..c536873 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) > -- > 1.7.5.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch