Merge change 9544

* changes:
  free surface buffers before trying to allocate new ones, so we have more chance of success