Denys Vlasenko | 2 Mar 2011 04:15

Re: [PATCH 2/3] free allocated iface and liface before return

On Tuesday 01 March 2011 12:38, Alexey Fomenko wrote:
> xstrdup allocates buffer to iface, liface. Needs to be freed.
> 
> Signed-off-by: Alexey Fomenko <ext-alexey.fomenko <at> nokia.com>
> ---
>  networking/ifupdown.c |    7 +++++--
>  networking/nameif.c   |    6 ++----
>  2 files changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/networking/ifupdown.c b/networking/ifupdown.c
> index 59df4e8..52fe8d8 100644
> --- a/networking/ifupdown.c
> +++ b/networking/ifupdown.c
>  <at>  <at>  -1220,13 +1220,13  <at>  <at>  int ifupdown_main(int argc UNUSED_PARAM, char **argv)
>  				/* ifup */
>  				if (iface_state) {
>  					bb_error_msg("interface %s already configured", iface);
> -					continue;
> +					goto next;
>  				}
>  			} else {
>  				/* ifdown */
>  				if (!iface_state) {
>  					bb_error_msg("interface %s not configured", iface);
> -					continue;
> +					goto next;
>  				}
>  			}
>  			llist_free(state_list, free);
>  <at>  <at>  -1316,6 +1316,9  <at>  <at>  int ifupdown_main(int argc UNUSED_PARAM, char **argv)
>  			fclose(state_fp);
>  			llist_free(state_list, free);
>  		}
> +	next:
> +		free(iface);
> +		free(liface);
>  	}
>  
>  	return any_failures;
> diff --git a/networking/nameif.c b/networking/nameif.c
> index d02c2c1..ba73450 100644
> --- a/networking/nameif.c
> +++ b/networking/nameif.c
>  <at>  <at>  -155,10 +155,8  <at>  <at>  int nameif_main(int argc, char **argv)
>  		bb_show_usage();
>  
>  	if (argc) {
> -		while (*argv) {
> -			char *ifname = xstrdup(*argv++);
> -			prepend_new_eth_table(&clist, ifname, *argv++);
> -		}
> +		while (*argv)
> +			prepend_new_eth_table(&clist, *argv++, *argv++);

The order of two ++ ops above is undefined.

>  	} else {
>  		parser = config_open(fname);
>  		while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL))

Applied with small changes. Thanks.
--

-- 
vda

Gmane