Try freeing them drom the last in the array to the first

[pascal] For i := fAllSockets.numsockets-1 downto 1 Do
begin
socket := PXTCPSocketArray(fAllSockets.sockets)[i];
SDLNet_TCP_Close(socket);
End; [/pascal]

If its using a list and you free an item it may be removed form the list, making the end of the list smaller so when it tries the next one its an access violation because there is no longer an object in that position.

(This is a guess and may be incorrect)