[pacman-dev] [PATCH 2/6] pacman.c: free string commandline options

Allan McRae allan at archlinux.org
Wed Jan 15 02:07:03 EST 2014


On 14/01/14 14:01, Andrew Gregory wrote:
> Plugs a memory leak when values were passed twice.
> 

I'd much prefer we aborted instead.  Specifying options twice is a sign
of an error on the users behalf.

Allan

> Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
> ---
>  src/pacman/pacman.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
> index 1fb447c..748bc54 100644
> --- a/src/pacman/pacman.c
> +++ b/src/pacman/pacman.c
> @@ -443,9 +443,11 @@ static int parsearg_global(int opt)
>  			config->noprogressbar = 1;
>  			break;
>  		case OP_GPGDIR:
> +			free(config->gpgdir);
>  			config->gpgdir = strdup(optarg);
>  			break;
>  		case OP_LOGFILE:
> +			free(config->logfile);
>  			config->logfile = strndup(optarg, PATH_MAX);
>  			break;
>  		case OP_NOCONFIRM:
> @@ -453,10 +455,12 @@ static int parsearg_global(int opt)
>  			break;
>  		case OP_DBPATH:
>  		case 'b':
> +			free(config->dbpath);
>  			config->dbpath = strdup(optarg);
>  			break;
>  		case OP_ROOT:
>  		case 'r':
> +			free(config->rootdir);
>  			config->rootdir = strdup(optarg);
>  			break;
>  		case OP_VERBOSE:
> @@ -623,6 +627,7 @@ static int parsearg_trans(int opt)
>  			break;
>  		case OP_PRINTFORMAT:
>  			config->print = 1;
> +			free(config->print_format);
>  			config->print_format = strdup(optarg);
>  			break;
>  		default:
> 



More information about the pacman-dev mailing list