Index: src/vehicle.cpp =================================================================== --- src/vehicle.cpp (revision 13680) +++ src/vehicle.cpp (working copy) @@ -2493,19 +2493,17 @@ for (; 0 < length; original = original->Next(), copy++, length--) { /* First we need to copy the vehicle itself. - * However there is an issue as the cargo list isn't copied. - * To avoid restoring invalid pointers we start by swapping the cargo list with an empty one. */ - CargoList::List empty_packets; - original->cargo.packets.swap(empty_packets); + * This will however make the cargo list of the copy share the memory with + * the original cargo list. As the original list can be destroyed later on, + * construct a new empty list for the copy in-place. The cargo packets are + * saved separately later on. */ memcpy(copy, original, sizeof(Vehicle)); + new(©->cargo.packets) CargoList::List(); /* No need to do anything else if the cargo list is empty. * It really doesn't matter if we swap an empty list with an empty list. */ if (original->cargo.Empty()) continue; - /* And now we swap the cargo lists back. The vehicle now has it's cargo again. */ - original->cargo.packets.swap(empty_packets); - /* The vehicle contains some cargo so we will back up the cargo as well. * We only need to store the packets and not which vehicle they came from. * We will still be able to put them together with the right vehicle when restoring. */