* fix test

* cleanup strval2 on if an error during the OnLoad was encountered.
This commit is contained in:
jonathan keinan 2025-02-04 13:19:24 +02:00 committed by YaacovHazan
parent 294492dbf2
commit f7353db7eb
2 changed files with 14 additions and 13 deletions

View File

@ -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;
}

View File

@ -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"]] {