corrected runtime errors caused at free()