Fix bugs: memory allocated error