(you don't have to strictly follow this form)

**Describe the bug**
The following query leads to OOM if server was built with thread sanitizer.

```sql
SELECT range(65535) FROM system.one ARRAY JOIN range(65536) AS number

{
        setThreadName("Formatter");
        try
        {
            auto & unit = processing_units[current_unit_number];
            assert(unit.status = READY_TO_FORMAT);
            
            
            unit.segment.resize(DBMS_DEFAULT_BUFFER_SIZE);
            unit.actual_memory_size = 0;
            BufferWithOutsideMemory<WriteBuffer> out_buffer(unit.segment);
            
            unit.segment.resize(0);
            auto formatter = internal_formatter_creator(out_buffer);
            switch (unit.type)
            {
                case ProcessingUnitType::START :
                {
                    formatter->doWritePrefix();
                    break;
                }
                case ProcessingUnitType::PLAIN :
                {
                    formatter->consume(std::move(unit.chunk));
                    break;
                }
                case ProcessingUnitType::TOTALS :
                {