[Tarantool-patches] [PATCH v20 1/7] box/schema: make sure hashes are created

Serge Petrenko sergepetrenko at tarantool.org
Mon Apr 5 12:28:50 MSK 2021



02.04.2021 15:34, Cyrill Gorcunov пишет:
> These are critical structures, strictly speaking
> if malloc has failed we're likely under heavy memory
> pressure and won't continue anyway but better to exit
> explicitly.
>
> In-scope-of #4642
>
> Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
> ---
>   src/box/schema.cc | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/src/box/schema.cc b/src/box/schema.cc
> index 963278b19..89904e4d2 100644
> --- a/src/box/schema.cc
> +++ b/src/box/schema.cc
> @@ -372,6 +372,13 @@ schema_init(void)
>   	funcs = mh_i32ptr_new();
>   	funcs_by_name = mh_strnptr_new();
>   	sequences = mh_i32ptr_new();
> +
> +	if (spaces == NULL || spaces_by_name == NULL ||
> +	    funcs == NULL || funcs_by_name == NULL ||
> +	    sequences == NULL) {
> +		panic("Can't allocate schema hashes");
> +	}

I've just noticed, all the mh_..._new methods will fail on a null 
dereference
even before returning. So the check above doesn't make much sense.

But I see that some other places have this check
`if (smth = mh_smth_new() == NULL)` and set an error.

Am I missing something?
> +
>   	/*
>   	 * Create surrogate space objects for the mandatory system
>   	 * spaces (the primal eggs from which we get all the

-- 
Serge Petrenko



More information about the Tarantool-patches mailing list