]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Gracefully deal with malloc failures in module_ctx.h
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 1 Dec 2021 14:53:31 +0000 (08:53 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 1 Dec 2021 20:07:02 +0000 (14:07 -0600)
src/lib/server/module_ctx.h

index 904c7a733affab2e26f10efa9c6a121f28b54271..60ec5bf0393c4d5e42128aa394b7e3d89ffe8ab1 100644 (file)
@@ -71,7 +71,8 @@ static module_ctx_t *module_ctx_from_inst(TALLOC_CTX *ctx, module_inst_ctx_t con
 {
        module_ctx_t *nmctx;
 
-       MEM(nmctx = talloc_zero(ctx, module_ctx_t));
+       nmctx = talloc_zero(ctx, module_ctx_t);
+       if (unlikely(!nmctx)) return NULL;
        nmctx->inst = mctx->inst;
 
        return nmctx;
@@ -84,7 +85,8 @@ static module_ctx_t *module_ctx_from_thread_inst(TALLOC_CTX *ctx, module_thread_
 {
        module_ctx_t *nmctx;
 
-       MEM(nmctx = talloc_zero(ctx, module_ctx_t));
+       nmctx = talloc_zero(ctx, module_ctx_t);
+       if (unlikely(!nmctx)) return NULL;
        nmctx->inst = mctx->inst;
        nmctx->thread = mctx->thread;
 
@@ -99,6 +101,7 @@ static module_ctx_t *module_ctx_dup(TALLOC_CTX *ctx, module_ctx_t const *mctx)
        module_ctx_t *nmctx;
 
        nmctx = talloc_zero(ctx, module_ctx_t);
+       if (unlikely(!nmctx)) return NULL;
        memcpy(nmctx, mctx, sizeof(*nmctx));
 
        return nmctx;