Re: [PATCH] builtin-update-index.c (add_file_to_cache): Don't leak a cache entry.

From: Jim Meyering <jim@meyering.net>
Date: 2007-02-18 20:10:21
Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Fri, 16 Feb 2007, Jim Meyering wrote:
>>
>> -	if (index_path(ce->sha1, path, &st, !info_only))
>> +	if (index_path(ce->sha1, path, &st, !info_only)) {
>> +		free(ce);
>>  		return -1;
>> +	}
>
> Well, the only user of this does:
>
> 	if (add_file_to_cache(p))
> 		die("Unable to process file %s", path);
>
> so the leak is very shortlived ;)

True... for now, and probably for ever after, but what if?  However,
the goal in plugging a leak like this is not to avoid wasting memory,
but rather to avoid spending time investigating it, again and again.
It's analogous to making your code compile warning-free.  When a new
warning/leak pops up, it's easy to spot (in case it really does matter),
not obscured by lots of older ones.

There are other ways to mark a leak as ignorable, but this method works
across all leak-detecting tools.

If you'd prefer to avoid the cost of a technically-unnecessary free,
give it a different name, so it can be a no-op most of the time, and
"free" only when compiled in leak-checking mode.
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Sun Feb 18 20:36:21 2007

This archive was generated by hypermail 2.1.8 : 2007-02-18 20:38:16 EST