fix invalid free()ing