fixed some potential realloc()-related memory leaks