[pacman-dev] [PATCH 4/4] Move NULL check before dereference

Andrew Gregory andrew.gregory.8 at gmail.com
Tue Jan 28 12:32:13 EST 2014


On 01/28/14 at 05:50pm, Silvan Jegen wrote:
> Signed-off-by: Silvan Jegen <s.jegen at gmail.com>
> ---
>  src/pacman/pacman.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
> index 7329f0f..1d821ef 100644
> --- a/src/pacman/pacman.c
> +++ b/src/pacman/pacman.c
> @@ -262,13 +262,13 @@ static void setuseragent(void)
>  static void cleanup(int ret)
>  {
>  	/* free alpm library resources */

This comment applies specifically to the alpm_release call and either
needs to be moved with it or deleted.

> -	if(config->handle && alpm_release(config->handle) == -1) {
> -		pm_printf(ALPM_LOG_ERROR, "error releasing alpm library\n");
> -	}
> -
> -	/* free memory */
> -	FREELIST(pm_targets);
>  	if(config) {
> +		if(config->handle && alpm_release(config->handle) == -1) {
> +			pm_printf(ALPM_LOG_ERROR, "error releasing alpm library\n");
> +		}
> +
> +		/* free memory */
> +		FREELIST(pm_targets);

pm_targets is independent of config and needs to be freed whether
config is NULL or not.

>  		config_free(config);
>  		config = NULL;
>  	}
> -- 
> 1.8.5.3


More information about the pacman-dev mailing list