Fix parent and children index calculation

The heap array starts at index 0, not at index 1.
Destroy heap and close file on malloc failure