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

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

 



Am 24.09.24 um 08:32 schrieb Patrick Steinhardt:
> diff --git a/reftable/basics.c b/reftable/basics.c
> index 3350bbffa23..82bfb807631 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++)
> +		free(names[i]);
> +	free(names);

These are allocated with reftable_realloc() under the hood, so they'd
better be passed to reftable_free() instead, no?

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