mcenc: check allocations and cleanup