From: Alan T. DeKok Date: Tue, 5 Apr 2022 14:46:15 +0000 (-0400) Subject: check for error before allocating the VP X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4f396c67064dfd460305c141b065d915320afa5;p=thirdparty%2Ffreeradius-server.git check for error before allocating the VP which also makes the code a little cleaner. --- diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index e2a503c7c4..b672d0f3e0 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -175,6 +175,13 @@ fr_pair_t *fr_pair_root_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da) { fr_pair_t *vp; +#ifndef NDEBUG + if (da->type != FR_TYPE_GROUP) { + fr_strerror_const("Root must be a group type"); + return NULL; + } +#endif + vp = talloc_zero(ctx, fr_pair_t); if (unlikely(!vp)) { fr_strerror_const("Out of memory"); @@ -188,20 +195,7 @@ fr_pair_t *fr_pair_root_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da) vp->da = da; -#ifndef NDEBUG - switch (da->type) { - case FR_TYPE_GROUP: -#endif - fr_pair_list_init(&vp->children); - -#ifndef NDEBUG - break; - - default: - fr_strerror_const("Root must be a group type"); - return NULL; - } -#endif + fr_pair_list_init(&vp->children); return vp; }