]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
check for error before allocating the VP
authorAlan T. DeKok <aland@freeradius.org>
Tue, 5 Apr 2022 14:46:15 +0000 (10:46 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 7 Apr 2022 15:23:34 +0000 (11:23 -0400)
which also makes the code a little cleaner.

src/lib/util/pair.c

index e2a503c7c431c1224357b71340e6196cba6dd969..b672d0f3e0643291ed64594b5308c9bf0e4ab62c 100644 (file)
@@ -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;
 }