Re: [PATCH v3 05/22] reftable/basics: handle allocation failures in `parse_names()`

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 30.09.24 um 10:08 schrieb Patrick Steinhardt:
> diff --git a/reftable/basics.c b/reftable/basics.c
> index 3350bbffa2..5ae6e6acdd 100644
> --- a/reftable/basics.c
> +++ b/reftable/basics.c
> @@ -152,14 +152,26 @@ void parse_names(char *buf, int size, char ***namesp)
>  		}
>  		if (p < next) {
>  			REFTABLE_ALLOC_GROW(names, names_len + 1, names_cap);
> -			names[names_len++] = xstrdup(p);
> +			if (!names)
> +				goto err;
> +
> +			names[names_len] = strdup(p);
> +			if (!names[names_len++])
> +				goto err;
>  		}
>  		p = next + 1;
>  	}
>
>  	REFTABLE_REALLOC_ARRAY(names, names_len + 1);
>  	names[names_len] = NULL;
> -	*namesp = names;
> +
> +	return names;
> +
> +err:
> +	for (size_t i = 0; i < names_len; i++)
> +		reftable_free(names[i]);

If you use reftable_free() here, you'd better use reftable_strdup()
instead of strdup(3) above.

René






[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux