From 5fd9756d2e1e73371c29e981d0c5a7a91976a27c Mon Sep 17 00:00:00 2001 From: Binbin <binloveplay1314@qq.com> Date: Sun, 11 Jun 2023 09:11:16 +0800 Subject: [PATCH] Fix ACLAppendUserForLoading memory leak when merge error (#12296) This leak will only happen in loadServerConfigFromString, that is, when we are loading a redis.conf, and the user is wrong. Because it happens in loadServerConfigFromString, redis will exit if there is an error, so this is actually just a cleanup. --- src/acl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/acl.c b/src/acl.c index ebf152aaa..f518dd1cb 100644 --- a/src/acl.c +++ b/src/acl.c @@ -2112,10 +2112,6 @@ int ACLAppendUserForLoading(sds *argv, int argc, int *argc_err) { return C_ERR; } - /* Try to apply the user rules in a fake user to see if they - * are actually valid. */ - user *fakeuser = ACLCreateUnlinkedUser(); - /* Merged selectors before trying to process */ int merged_argc; sds *acl_args = ACLMergeSelectorArguments(argv + 2, argc - 2, &merged_argc, argc_err); @@ -2124,6 +2120,10 @@ int ACLAppendUserForLoading(sds *argv, int argc, int *argc_err) { return C_ERR; } + /* Try to apply the user rules in a fake user to see if they + * are actually valid. */ + user *fakeuser = ACLCreateUnlinkedUser(); + for (int j = 0; j < merged_argc; j++) { if (ACLSetUser(fakeuser,acl_args[j],sdslen(acl_args[j])) == C_ERR) { if (errno != ENOENT) {