Merge "Fix memory corruption issue when unregistering surfaces" into flounder