[pacman-dev] [PATCH] fixed erroneous memory access to newurl in alpm_db_remove_server

Allan McRae allan at archlinux.org
Mon Jul 30 19:08:13 EDT 2012


On 31/07/12 05:57, Barbu Paul - Gheorghe wrote:
> 
> Signed-off-by: Barbu Paul - Gheorghe <barbu.paul.gheorghe at gmail.com>
> ---
>  lib/libalpm/db.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
> index bf9c3f0..26b6250 100644
> --- a/lib/libalpm/db.c
> +++ b/lib/libalpm/db.c
> @@ -198,16 +198,20 @@ int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const char *url)
>  	if(!newurl) {
>  		return -1;
>  	}
> +
>  	db->servers = alpm_list_remove_str(db->servers, newurl, &vdata);
> -	free(newurl);
> +
> +	int ret = 1;

Our current coding standard is to declare all variables at the start of
the block.

>  	if(vdata) {
>  		_alpm_log(db->handle, ALPM_LOG_DEBUG, "removed server URL from database '%s': %s\n",
>  				db->treename, newurl);
>  		free(vdata);

Instead of creating a new variable, why not just free(newurl) here and
keep the return?

> -		return 0;
> +		ret = 0;
>  	}
>  
> -	return 1;
> +	free(newurl);
> +	return ret;
>  }
>  
>  /** Get the name of a package database. */
> 



More information about the pacman-dev mailing list