From b92a05e18ff02d59218b79d7acbea10a982da58f Mon Sep 17 00:00:00 2001 From: chenjinhao Date: Mon, 9 Jun 2025 14:34:03 +0800 Subject: [PATCH 1/2] glusterd: fix memleak in glusterd_mgmt_handshake asan reports: Direct leak of 4386 byte(s) in 34 object(s) allocated from: #0 0x7ff3b72efbb8 in __interceptor_malloc (/lib64/libasan.so.5+0xefbb8) #1 0x7ff3b6902420 in __gf_malloc (/lib64/libglusterfs.so.0+0x102420) #2 0x7ff3b6876e18 in dict_allocate_and_serialize (/lib64/libglusterfs.so.0+0x76e18) #3 0x7ff3aa5ec701 in glusterd_mgmt_handshake glusterd-handshake.c:2212 #4 0x7ff3aa5ee2cc in __glusterd_peer_dump_version_cbk glusterd-handshake.c:2388 #5 0x7ff3aa5b58ca in glusterd_big_locked_cbk glusterd-rpc-ops.c:217 #6 0x7ff3b642ffcb in rpc_clnt_handle_reply rpc-clnt.c:780 #7 0x7ff3b64307e9 in rpc_clnt_notify rpc-clnt.c:957 #8 0x7ff3b6425c2c in rpc_transport_notify (/lib64/libgfrpc.so.0+0x25c2c) #9 0x7ff3a880d874 in socket_event_poll_in_async socket.c:2531 #10 0x7ff3a882828e in socket_event_poll_in ../../../../libglusterfs/src/glusterfs/async.h:189 #11 0x7ff3a882828e in socket_event_handler socket.c:2963 #12 0x7ff3a882828e in socket_event_handler socket.c:2883 #13 0x7ff3b69af776 in event_dispatch_epoll_handler event-epoll.c:640 #14 0x7ff3b69af776 in event_dispatch_epoll_worker event-epoll.c:751 #15 0x7ff3b48082fe in start_thread pthread_create.c:479 #16 0x7ff3b3e39dd2 in __GI___clone (/lib64/libc.so.6+0x39dd2) Fixes: #4558 Signed-off-by: chenjinhao --- xlators/mgmt/glusterd/src/glusterd-handshake.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c index 42aea78a002..a33b267aad4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handshake.c +++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c @@ -2282,6 +2282,9 @@ glusterd_mgmt_handshake(xlator_t *this, glusterd_peerctx_t *peerctx) if (ret && frame) STACK_DESTROY(frame->root); + if (req.hndsk.hndsk_val) + GF_FREE(req.hndsk.hndsk_val); + return ret; } From c3bee87888d1e170582d24f6ed6e28f80d525762 Mon Sep 17 00:00:00 2001 From: chenjinhao Date: Mon, 9 Jun 2025 14:37:49 +0800 Subject: [PATCH 2/2] mem-pool: update size in __gf_free size in mem_acct data struct, which indicates total size allocated for data-type, is not updated correctly. size will increase when GF_MALLOC is called, however, it never get a decreasement in GF_FREE. So fix it here, otherwise the wrong size may mislead mempool memleak anlysis. Fixes: #4558 Signed-off-by: chenjinhao --- libglusterfs/src/mem-pool.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index f053fdceae2..1be523212a3 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -384,6 +384,7 @@ __gf_free(void *free_ptr) LOCK(&mem_acct->rec[header->type].lock); { list_del(&header->acct_list); + mem_acct->rec[header->type].size -= header->size; } UNLOCK(&mem_acct->rec[header->type].lock); #endif