Fixed a bug in heap allocation