rls: Fix memory leak with duplicate entries in lists
- When duplicate detection is requested, free the string and container
- When duplicate detection is not requested, insert the duplicate anyway
(cherry picked from commit 5cd3bd3a1bbcc9edffe31c0b1fdf11da43023b2c)