From f7353db7ebbcacec876c34d881b82164a32d88aa Mon Sep 17 00:00:00 2001 From: jonathan keinan Date: Tue, 4 Feb 2025 13:19:24 +0200 Subject: [PATCH] * fix test * cleanup strval2 on if an error during the OnLoad was encountered. --- tests/modules/moduleconfigs.c | 25 +++++++++++++------------ tests/unit/moduleapi/moduleconfigs.tcl | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/modules/moduleconfigs.c b/tests/modules/moduleconfigs.c index 26ab47ec67..3c233576d4 100644 --- a/tests/modules/moduleconfigs.c +++ b/tests/modules/moduleconfigs.c @@ -165,6 +165,17 @@ int registerBlockCheck(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_OK; } +void cleanup(RedisModuleCtx *ctx) { + if (strval) { + RedisModule_FreeString(ctx, strval); + strval = NULL; + } + if (strval2) { + RedisModule_FreeString(ctx, strval2); + strval2 = NULL; + } +} + int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { REDISMODULE_NOT_USED(argv); REDISMODULE_NOT_USED(argc); @@ -264,22 +275,12 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_OK; err: - if (strval) { - RedisModule_FreeString(ctx, strval); - strval = NULL; - } + cleanup(ctx); return REDISMODULE_ERR; } int RedisModule_OnUnload(RedisModuleCtx *ctx) { REDISMODULE_NOT_USED(ctx); - if (strval) { - RedisModule_FreeString(ctx, strval); - strval = NULL; - } - if (strval2) { - RedisModule_FreeString(ctx, strval2); - strval2 = NULL; - } + cleanup(ctx); return REDISMODULE_OK; } diff --git a/tests/unit/moduleapi/moduleconfigs.tcl b/tests/unit/moduleapi/moduleconfigs.tcl index 2c6b4b3b8e..62082ae1f9 100644 --- a/tests/unit/moduleapi/moduleconfigs.tcl +++ b/tests/unit/moduleapi/moduleconfigs.tcl @@ -319,7 +319,7 @@ start_server {tags {"modules"}} { # missing LoadConfigs call catch {exec src/redis-server --loadmodule "$testmodule" noload --moduleconfigs.string "hello"} err - assert_match {*Module Configurations were not set, likely a missing LoadConfigs call. Unloading the module.*} $err + assert_match {*Module Configurations were not set, missing LoadConfigs call. Unloading the module.*} $err # successful start_server [list overrides [list loadmodule "$testmodule" moduleconfigs.string "bootedup" moduleconfigs.enum two moduleconfigs.flags "two four"]] {