From 05292e342f95c8e191e4fa85011e39372660cfec Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Wed, 6 Nov 2019 08:25:07 +0000 Subject: Improved some error handling in examples --- src/module.c | 4 +++- src/modules/helloacl.c | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/module.c b/src/module.c index 17fca5e1d..5517a9f59 100644 --- a/src/module.c +++ b/src/module.c @@ -5216,7 +5216,7 @@ RedisModuleUser *RM_CreateModuleUser(const char *name) { RedisModuleUser *new_user = zmalloc(sizeof(RedisModuleUser)); new_user->user = ACLCreateUnlinkedUser(); - /* Free the previous temporarily assigned name to assign the new one */ + /* Free the temporarily assigned name to assign the new one */ sdsfree(new_user->user->name); new_user->user->name = sdsnew(name); return new_user; @@ -5262,6 +5262,8 @@ RedisModuleAuthCtx *RM_CreateAuthCtx(RedisModuleUserChangedFunc callback, void * RedisModuleAuthCtx *auth_ctx = zmalloc(sizeof(RedisModuleAuthCtx)); auth_ctx->callback = callback; auth_ctx->privdata = privdata; + auth_ctx->module = NULL; + auth_ctx->authenticated_client = NULL; return auth_ctx; } diff --git a/src/modules/helloacl.c b/src/modules/helloacl.c index 95dcb09c8..cf4819082 100644 --- a/src/modules/helloacl.c +++ b/src/modules/helloacl.c @@ -92,7 +92,11 @@ int AuthGlobalCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv } RedisModuleAuthCtx *auth_ctx = RedisModule_CreateAuthCtx(HelloACL_UserChanged, NULL); - RedisModule_AuthClientWithUser(ctx, global, auth_ctx); + if (RedisModule_AuthClientWithUser(ctx, global, auth_ctx) == + REDISMODULE_ERR) { + return RedisModule_ReplyWithError(ctx, "Couldn't authenticate client"); + } + global_auth_ctx = auth_ctx; return RedisModule_ReplyWithSimpleString(ctx, "OK"); -- cgit v1.2.1