diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 2ee368b83..bef5aa5e6 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -42,6 +42,16 @@ void appctx_shut(struct appctx *appctx); struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp); +/* Helper function to call .init applet callback function, if it exists. Returns 0 + * on success and -1 on error. + */ +static inline int appctx_init(struct appctx *appctx) +{ + if (appctx->applet->init) + return appctx->applet->init(appctx); + return 0; +} + /* Releases an appctx previously allocated by appctx_new(). */ static inline void __appctx_free(struct appctx *appctx) { diff --git a/src/stream.c b/src/stream.c index dd3358e48..29d1a60b5 100644 --- a/src/stream.c +++ b/src/stream.c @@ -997,9 +997,8 @@ enum act_return process_use_service(struct act_rule *rule, struct proxy *px, return ACT_RET_ERR; /* Finish initialisation of the context. */ - memset(&appctx->ctx, 0, sizeof(appctx->ctx)); appctx->rule = rule; - if (appctx->applet->init && !appctx->applet->init(appctx)) + if (appctx_init(appctx) == -1) return ACT_RET_ERR; } else