unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: Ethan Glasser-Camp <glasse@cs.rpi.edu>, notmuch@notmuchmail.org
Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
Subject: Re: [PATCH] Free the results of scandir()
Date: Tue, 07 Feb 2012 00:21:21 +0200	[thread overview]
Message-ID: <878vkfppr2.fsf@nikula.org> (raw)
In-Reply-To: <1328565769-29414-1-git-send-email-glasse@cs.rpi.edu>

On Mon,  6 Feb 2012 17:02:49 -0500, Ethan Glasser-Camp <glasse@cs.rpi.edu> wrote:
> From: Ethan Glasser-Camp <ethan@betacantrips.com>
> 
> 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

  reply	other threads:[~2012-02-06 22:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-06 22:02 [PATCH] Free the results of scandir() Ethan Glasser-Camp
2012-02-06 22:21 ` Jani Nikula [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-02-07 10:05 Ethan Glasser-Camp
2012-02-07 10:10 ` Dmitry Kurochkin
2012-02-07 10:13   ` Ethan Glasser-Camp
2012-02-07 10:30 ` Tomi Ollila
2012-02-15  3:47 ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878vkfppr2.fsf@nikula.org \
    --to=jani@nikula.org \
    --cc=ethan@betacantrips.com \
    --cc=glasse@cs.rpi.edu \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).