s3:netapi: Fix a leak in libnetapi_net_init()
authorPavel Kalugin <pkalugin@inno.tech>
Sun, 20 Aug 2023 20:50:38 +0000 (23:50 +0300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 14 Sep 2023 21:35:29 +0000 (21:35 +0000)
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 <pkalugin@inno.tech>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/lib/netapi/netapi.c

index cbf9068ee618531eb75dc5a077798f1e5b52be5f..9c049a841114fb2ee545b7409c12db121620bb80 100644 (file)
@@ -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);