From: Pavel Kalugin Date: Sun, 20 Aug 2023 20:50:38 +0000 (+0300) Subject: s3:netapi: Fix a leak in libnetapi_net_init() X-Git-Tag: tevent-0.16.0~549 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04d20c3aebd229ba6150950ad46356189b3384bb;p=thirdparty%2Fsamba.git s3:netapi: Fix a leak in libnetapi_net_init() Allow libnetapi_net_init() to be called more than once without leaking libnetapi_ctx allocated on a previous call, which is currently the case in the `net rpc` code. Signed-off-by: Pavel Kalugin Reviewed-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index cbf9068ee61..9c049a84111 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -119,8 +119,14 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context, { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; - TALLOC_CTX *frame = talloc_stackframe(); + TALLOC_CTX *frame = NULL; + + if (stat_ctx != NULL && libnetapi_initialized) { + *context = stat_ctx; + return NET_API_STATUS_SUCCESS; + } + frame = talloc_stackframe(); ctx = talloc_zero(frame, struct libnetapi_ctx); if (!ctx) { TALLOC_FREE(frame);