Heap allocation problem