[libvirt] [libvirt-php] Fixed set_error when argument is NULL

Michal Novotny minovotn at redhat.com
Mon Apr 4 08:32:16 UTC 2011


On 04/02/2011 05:20 AM, Lyre wrote:
> Avoid freeing a NULL pointer
> ---
>  src/libvirt-php.c |    8 ++++++--
>  1 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/src/libvirt-php.c b/src/libvirt-php.c
> index 6a76f45..66b1de9 100644
> --- a/src/libvirt-php.c
> +++ b/src/libvirt-php.c
> @@ -237,12 +237,16 @@ PHP_MINFO_FUNCTION(libvirt)
>  */
>  void set_error(char *msg TSRMLS_DC)
>  {
> -	if (msg == NULL) {
> +	if (LIBVIRT_G (last_error) != NULL)
> +	{
>  		efree(LIBVIRT_G (last_error));
> +	}
> +
> +	if (msg == NULL) {
> +		LIBVIRT_G (last_error) = NULL;
>  		return;
>  	}
>  	php_error_docref(NULL TSRMLS_CC, E_WARNING,"%s",msg);
> -	if (LIBVIRT_G (last_error)!=NULL) efree(LIBVIRT_G (last_error));
>  	LIBVIRT_G (last_error)=estrndup(msg,strlen(msg));
>  }
>  
Good pick. Thanks! Pushed now.

Michal

-- 
Michal Novotny <minovotn at redhat.com>, RHCE
Virtualization Team (xen userspace), Red Hat




More information about the libvir-list mailing list