From 6db268f40e7f3a18037560bca1724f2a2eb3441e Mon Sep 17 00:00:00 2001 From: Gagan Dhakrey Date: Sun, 5 Apr 2026 06:50:16 +0530 Subject: [PATCH] Fix thread leaks in helloblock module by detaching unjoined threads --- src/modules/helloblock.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/helloblock.c b/src/modules/helloblock.c index 44bb01081..5cafaabd7 100644 --- a/src/modules/helloblock.c +++ b/src/modules/helloblock.c @@ -14,6 +14,8 @@ #include "../redismodule.h" #include #include +#include +#include #include #include @@ -47,8 +49,9 @@ void *HelloBlock_ThreadMain(void *arg) { RedisModule_Free(targ); sleep(delay); + unsigned int seed = (unsigned int)time(NULL) ^ (unsigned int)(uintptr_t)pthread_self(); int *r = RedisModule_Alloc(sizeof(int)); - *r = rand(); + *r = rand_r(&seed); RedisModule_UnblockClient(bc,r); return NULL; } @@ -105,6 +108,7 @@ int HelloBlock_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int a RedisModule_AbortBlock(bc); return RedisModule_ReplyWithError(ctx,"-ERR Can't start thread"); } + pthread_detach(tid); return REDISMODULE_OK; } @@ -175,6 +179,7 @@ int HelloKeys_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int ar RedisModule_AbortBlock(bc); return RedisModule_ReplyWithError(ctx,"-ERR Can't start thread"); } + pthread_detach(tid); return REDISMODULE_OK; }