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 22D3D431FBC for ; Tue, 7 Feb 2012 02:06:43 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.54 X-Spam-Level: X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_SORBS_WEB=0.614] 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 fvnv3FprJ+sG for ; Tue, 7 Feb 2012 02:06:42 -0800 (PST) Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 82DBF431FB6 for ; Tue, 7 Feb 2012 02:06:42 -0800 (PST) X-Hash: S|436efe1a3ed5ebbf742d3717a4d2312265f22a30|8113652595f775174c43145e8c7f9b33 X-Countries: Cameroon, United States X-SMTP-From: accepted [195.24.209.22] [195.24.209.22] (localhost) {Cameroon} DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from :to:cc:subject:date:message-id; s=default; i=glasse@cs.rpi.edu; t=1328609200; x=1329214000; l=1314; bh=LudzVUYZyVaiDSVr5V+5o//Y wOA=; b=Jin60snVggEG+41xMAoov564/tSgXxNwv/sS1050cepE3kKP5H3Sl67Q d25cFPrjlLbnMFVzy4TEovmYJjzVYxzYqC/lRaS8NHrJTNtRF5aZqnuKgVZHovKO 5EeHpu1UFDGkwzkUznwKMdn98JlSK735XuK/J9IqK6wYNX6o2kA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc :subject:date:message-id; q=dns; s=default; b=kcGAKoT+RRkv/BxmFJ zIsLWIoL/RfiZbZ/Ch/jwT+eOwbzhg1p2BxELBERpcDUxrCH7E93F9JaVrS/UOE5 ZTZGb9L7jvzMS+XAk5glhorTLnVO4rDqLoMXC0MTZMdfHo4hpI2QGXwc2ZwRhG9q oEsnZxY40KHheXWGUaRniKfFY= X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00 X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit 15) Authentication-Results: cliffclavin.cs.rpi.edu; DKIM=neutral (none) header.from=glasse@cs.rpi.edu; SPF=neutral (mfrom; Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu X-Auth-Passed: cliffclavin.cs.rpi.edu:q17A6831075843 Auth:glasse X-Virus-Scanned-By: cliffclavin.cs.rpi.edu Received: from localhost ([195.24.209.22]) (authenticated bits=0) by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q17A6831075843 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 7 Feb 2012 05:06:22 -0500 (EST) (envelope-from glasse@cs.rpi.edu) From: Ethan Glasser-Camp To: notmuch@notmuchmail.org Subject: [PATCH] Free the results of scandir() Date: Tue, 7 Feb 2012 05:05:03 -0500 Message-Id: <1328609103-7870-1-git-send-email-glasse@cs.rpi.edu> X-Mailer: git-send-email 1.7.5.4 X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25 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 10:06:43 -0000 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. --- v3: I'm still learning the house style. Thanks Dmitry. notmuch-new.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index a569a54..8dbebb3 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