Re: [PATCH] taskset: fix memory leaks when exiting on error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 27, 2010 at 06:46:42AM -0300, Davidlohr Bueso wrote:
> From: Davidlohr Bueso <dave@xxxxxxx>
> Date: Wed, 27 Oct 2010 06:44:17 -0300
> Subject: [PATCH] taskset: fix memory leaks when exiting on error
> 
> Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
> ---
>  schedutils/taskset.c |   48 +++++++++++++++++++++++++++++++++++-------------
>  1 files changed, 35 insertions(+), 13 deletions(-)
> 
> diff --git a/schedutils/taskset.c b/schedutils/taskset.c
> index 201fc15..8094c5d 100644
> --- a/schedutils/taskset.c
> +++ b/schedutils/taskset.c
> @@ -125,8 +125,10 @@ int main(int argc, char *argv[])
>  
>  	buflen = 7 * cur_nbits;
>  	buf = malloc(buflen);
> -	if (!buf)
> +	if (!buf) {
> +		cpuset_free(cur_set);
>  		err(EXIT_FAILURE, _("malloc failed"));
> +	}
>  
>  	/*
>  	 * new_set is always used for the sched_setaffinity call
> @@ -134,12 +136,17 @@ int main(int argc, char *argv[])
>  	 * cpumask_t if the user's mask is shorter.
>  	 */
>  	new_set = cpuset_alloc(ncpus, &new_setsize, NULL);
> -	if (!new_set)
> +	if (!new_set) {
> +		free(buf);
> +		cpuset_free(cur_set);
>  		err(EXIT_FAILURE, _("cpuset_alloc failed"));
> +	}
>  
>  	if (pid) {
> -		if (sched_getaffinity(pid, cur_setsize, cur_set) < 0)
> -			err(EXIT_FAILURE, _("failed to get pid %d's affinity"), pid);
> +		if (sched_getaffinity(pid, cur_setsize, cur_set) < 0) {
> +			fprintf(stderr, _("failed to get pid %d's affinity"), pid);
> +			goto err_free;

 I know about this problem, but I have doubts that this pedantic point
 of view and the extra code makes any real effect. After exit() all 
 memory will be deallocated... I think it's better in this example to
 call err() and keep the code simple and readable.

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux