Thanks for working on this and writing a fix for this obscure bug. A couple of minor thoughts on the patch. We can avoid copying bitmaps by swapping pointers to them. There are now two opportunities for calloc to fail, and we leak memory if the second one fails. A simple fix is to call calloc once and split the result in half. Proposed patch attached.