BUG: unchecked malloc in heapsort
Merge pull request #5054 from larsmans/c-fixes

BUG: unchecked malloc in heapsort