I have a question about this function 'listDup' in alist.c
above this function, this is a comment sasy "The original list both on success or error is never modified."
but when copy->dup is NULL,and "out of memory" happens, the original list will be released.
Am I wrong?
Comment From: hwware
@AlbertGithubHome From the source code, the copied list was removed when the scenario you mentioned above happens, not the original list.. please check https://github.com/antirez/redis/blob/unstable/src/adlist.c#L268, and https://github.com/antirez/redis/blob/unstable/src/adlist.c#L274
Comment From: AlbertGithubHome
@hwware but the value of the copied list point to original list's value. It will be removed in function listRealase() and listEmpty().
https://github.com/antirez/redis/blob/unstable/src/adlist.c#L272
Comment From: hwware
Hello @AlbertGithubHome , from the source code if we did not set the duplicate method in the original list, then yes,if the copied list was released the original list value will be removed, however the duplicate method should be set by calling listSetDupMethod, in order to handle how to duplicate different types of objects, this was clearly mentioned in https://github.com/antirez/redis/blob/unstable/src/adlist.c#L245. an example of the use this function is https://github.com/antirez/redis/blob/unstable/src/acl.c#L211. But yes, this line of comment The original list both on success or error is never modified is not true if we did not set the listSetDupMethod, it might be a little bit misleading. please correct me if I miss anything @antirez @itamarhaber
Comment From: hwware
Keep in mind that this issue tracker should be used for reporting bugs or proposing improvements to the Redis server. Questions should be directed to the community: /r/redis subreddit the mailing list the redis tag at StackOverflow the irc channel #redis on freenode.
Comment From: AlbertGithubHome
@hwware I want to fix the bugs. Actually, adjusting the order of setting copy->free, the bugs can be fixed, I'll submit the code later.
Comment From: AlbertGithubHome
@hwware Sorry, I can't fix it. copy->dup and copy->free should be assigned at the same time. If we did not set the duplicate method in the original list, then yes,if the copied list was released the original list value may be removed. And orig->freen may not release memory. So it's up to users.
Comment From: hwware
@AlbertGithubHome yep you got the point :)
Comment From: hwware
pinging @oranagra @itamarhaber , question has been answered, recommend to close.