Release locks on error in `mergePages`.

Closes #276.