Just so I'm sure I understand how you are "copying" your lists.
You are creating two lists:
Element_List A;
Element_List B;
puplating list A with some stuff
Then making a "copy" of A into B?
ie. B = A is effectively doing the following?
1 2 3
|
B.mem_pFirst = A.mem_pFirst;
B.mem_pEnd = A.mem_pEnd;
B.mem_pCurrent = A.mem_pCurrent;
|
If that is the case, I have to ask a few questions first.
1) Why are you doing this? If you already have the contents in A, shouldn't you just reference that object directly?
2) What happens if you iterate through B to element 5 (just assuming you have a bunch of stuff in your list)
Then you iterate through A to element 5 and remove it from the list. At that point presumably you would free that memory as well.
B.mem_pCurrent is now pointing to an invalid memory space and will seg fault if you try to access it.
Even more simply, what happens if you now add an element to A? B.mem_pEnd will still be pointing to the old end of the list, and won't see the new element.
Basically what you are doing is very dangerous, and the double-free problem you are running into is only the tip of the ice berg. I suspect you will run into a lot of seg faults if you continue to link two instances of your list together like this.
Your list copy should be copying the actual contents of the list from one to the other. Effectively building a new list from the contents of the old. That way you can do whatever you want to list A (including delete it) without affecting list B.