Repository: redis/redis

Issue:
[BUG]There is a memory leak in ACLAppendUserForLoading  function
Notice!
- If a Redis module was involved, please open an issue in the module's repo instead!
- If you're using docker on Apple M1, please make sure the image you're using was compiled for ARM!


**Crash report**
There is a memory leak in the **ACLAppendUserForLoading**  function of  the \src\acl.c  
![image](https://github.com/redis/redis/assets/80461268/b17f4950-9b40-4489-b542-3ee72ca4c491)



**Additional information**
NA



Discussion:
thanks for the report, look like you are right, i am trying to see if i can write a test to fix it
This leak will only happen in loadServerConfigFromString, that is, when we load redis.conf
so if there is an error in this case, redis will exit

Patch:
diff --git a/src/acl.c b/src/acl.c
index ebf152aaaf3..f518dd1cb4a 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) {