-
Notifications
You must be signed in to change notification settings - Fork 480
Description
| Previous ID | SR-6420 |
| Radar | None |
| Original Reporter | @Lukasa |
| Type | Bug |
| Status | Closed |
| Resolution | Done |
Attachment: Download
Environment
Swift version 4.0.2 (swift-4.0.2-RELEASE)
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty
Additional Detail from JIRA
| Votes | 1 |
| Component/s | Foundation, libdispatch |
| Labels | Bug |
| Assignee | @alblue |
| Priority | Medium |
md5: 5a92d9c07669127110266896a5ed6515
Issue Description:
When using dispatch concurrent queues on Linux, if any of the code in the blocks dispatched to that queue cause CoreFoundation to allocate a TSD, that TSD will be leaked.
To see this, compile the attached C program. This C program creates 100 blocks that are dispatched to a concurrent queue, each of which creates a CFString. The program runs, then waits 40 seconds after all of the queue blocks have executed to allow libdispatch to tear down all its threads (if you observe the execution of this program in htop's tree mode, you'll see a large number of threads be spawned and then exit).
If you run this program using valgrind (e.g. using valgrind --leak-check=full ./a.out), you'll find that all of the Foundation TSDs that were allocated for the background threads have been leaked:
==2956== 80,088 bytes in 71 blocks are definitely lost in loss record 18 of 18
==2956== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2956== by 0x5050C21: _CFGetTSDCreateIfNeeded (in /usr/lib/swift/linux/libFoundation.so)
==2956== by 0x50D656F: __CFStringCreateImmutableFunnel3 (in /usr/lib/swift/linux/libFoundation.so)
==2956== by 0x50D70FF: CFStringCreateWithBytesNoCopy (in /usr/lib/swift/linux/libFoundation.so)
==2956== by 0x400C10: __main_block_invoke (in /code/a.out)
==2956== by 0x405E426: _dispatch_call_block_and_release (in /usr/lib/swift/linux/libdispatch.so)
==2956== by 0x4068DED: _dispatch_continuation_pop (in /usr/lib/swift/linux/libdispatch.so)
==2956== by 0x40683B4: _dispatch_async_redirect_invoke (in /usr/lib/swift/linux/libdispatch.so)
==2956== by 0x406D267: _dispatch_worker_thread (in /usr/lib/swift/linux/libdispatch.so)
==2956== by 0x5AAA183: start_thread (pthread_create.c:312)
==2956== by 0x5DBDFFC: clone (clone.S:111)