Simplify alloc_ids_core_mem() cleanup
Simplify alloc_ids_core_mem() cleanup

Avoid duplication of cleanup calls by adding cleanup labels to the end
of the function and jumping to them.

Also, if add_mem() fails, free the location just allocated, as well as
all old ones.

amitibo/ids,amitibo/ids