Fix problem reported by valgrind.

Replace memcpy with memmove in replace_string().
Fix buffer underun in restore_object()