Fixed malloc bug