From aabd64283d11fa9807bdf9fc650e106be5d63bb5 Mon Sep 17 00:00:00 2001 From: Ethan Glasser-Camp Date: Wed, 8 Feb 2012 01:50:05 +1900 Subject: [PATCH] [PATCH v2] Free the results of scandir() --- 14/632972f681aaaf0e13d54a4753218d07fac754 | 132 ++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 14/632972f681aaaf0e13d54a4753218d07fac754 diff --git a/14/632972f681aaaf0e13d54a4753218d07fac754 b/14/632972f681aaaf0e13d54a4753218d07fac754 new file mode 100644 index 000000000..71de71474 --- /dev/null +++ b/14/632972f681aaaf0e13d54a4753218d07fac754 @@ -0,0 +1,132 @@ +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 E5820431FAF + for ; Mon, 6 Feb 2012 22:50: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 aJHR4KKIUsKc for ; + Mon, 6 Feb 2012 22:50:43 -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 3E91F431FAE for ; Mon, 6 Feb 2012 22:50:43 -0800 + (PST) +X-Hash: + S|40e4c517ca0459386989b82fa84cfcb00c964d05|ab058044c63300b1ad8418f36616e81f +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=1328597441; x=1329202241; l=1324; bh=RQpuYYAQVZCaa6oTlvwssFG3 + WrI=; b=P11A6fwMJ1pOKwgqk1xINRibAzSKZFUrxxUDmO3pOZMcyYfeqTwJmLaJ + oXRWkiO55uF7vhTyh6eqd5MpmonyhmApUjYbCo+WFEXfP8BnZS8xsm+pwqXM0wpR + SiFRCtdg+UIQERbwtX++EpdHwr979EKLAvkWGs9RmZlWWRmvtQw= +DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc + :subject:date:message-id; q=dns; s=default; b=QXz70/Sq93rAKju6LX + GjRH2Uq9PJek+G3djd1xqIsHL6aPwBzWSbVm9lSyv17rjyPmf7tKowyBoCRGN+BK + 96RNLpasN7TPbRGF4lYDudkUU7jfChzP7QAUAQjxdGVm6fvuPwebDOYJBaqLtpmT + 18QvSLtg9bKmINgdQIO/7S5fk= +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:q176oJxj073383 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 q176oJxj073383 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); + Tue, 7 Feb 2012 01:50:34 -0500 (EST) + (envelope-from glasse@cs.rpi.edu) +From: Ethan Glasser-Camp +To: notmuch@notmuchmail.org +Subject: [PATCH v2] Free the results of scandir() +Date: Tue, 7 Feb 2012 01:50:05 -0500 +Message-Id: <1328597405-6437-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 06:50:44 -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. +--- + +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 + -- 2.26.2