Don't spill more blocks than we need to

Also fixes a memory leak
Hi @sryza , I think we should change here to:

```scala
if (bytesToSpill > 0) {
  while (!inMemoryBlocks.isEmpty) {
    ....
  }
}

Seems `bytesToSpill` will be negative and this loop will be jumped out.