Fix memory corruption issue when unregistering surfaces

No match.