Fix linked list corruption issues resulting in memory leaks