Fix error path memory leak
Fix bufCompact for non-empty buffers
Cleanup