Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5988] Memory leak in libdispatch on Linux #676

Open
swift-ci opened this issue Sep 26, 2017 · 4 comments
Open

[SR-5988] Memory leak in libdispatch on Linux #676

swift-ci opened this issue Sep 26, 2017 · 4 comments

Comments

@swift-ci
Copy link

Previous ID SR-5988
Radar rdar://problem/34650486
Original Reporter oc243 (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s libdispatch
Labels Bug
Assignee None
Priority Medium

md5: 80b03af9cefdb8950af898e9b1733df6

Issue Description:

Running the code below on Linux leaks memory, but it works fine on Darwin. I don't think that the code should be leaking memory (due to the wait). Swapping the `x=x+1` for the `print()` also leaks.

import Dispatch

func foo(q: DispatchQueue, g: DispatchGroup) {
  for _ in 0..<200 {
    q.async(group: g) {
      print()
    }
  }
  g.wait()
}

let g = DispatchGroup()
let q1 = DispatchQueue(label: "com.queue", attributes: .concurrent)

while true {
  foo(q: q1, g:g)
}
swift --version
Swift version 4.0 (swift-4.0-RELEASE)
Target: x86_64-unknown-linux-gnu

My investigations suggest that the following calloc of 64 bytes is never freed:

0 libc-2.23.so 0x00007fe837b88fba __calloc + 682 at malloc.c:3199
1 libdispatch.so 0x00007fe83a195854 _dispatch_continuation_alloc_from_heap + 36
2 libdispatch.so 0x00007fe83a1a2e5f dispatch_group_async + 207
3 libdispatch.so 0x00007fe83a1b7b9a Dispatch.DispatchQueue.async(group: Swift.Optional<Dispatch.DispatchGroup>, qos: Dispatch.DispatchQoS, flags: Dispatch.DispatchWorkItemFlags, execute: @convention(block) () -> ()) -> () + 31
@swift-ci
Copy link
Author

Comment by Oliver Chick (JIRA)

@swift-ci create

@weissi
Copy link
Member

weissi commented Sep 26, 2017

just FYI, valgrind sees them as lost but still reachable. The continuations don't seem to be reused properly.

==27516== 406,016 bytes in 6,344 blocks are still reachable in loss record 21 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B7853: _dispatch_continuation_alloc_from_heap (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C4E5E: dispatch_group_async (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D9B99: _T08Dispatch0A5QueueC5asyncyAA0A5GroupCSg5group_AA0A3QoSV3qosAA0A13WorkItemFlagsV5flagsyyXB7executetF (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40174E: main (in /home/jweiss/test)
==27516== 
==27516== 406,016 bytes in 6,344 blocks are still reachable in loss record 22 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B7853: _dispatch_continuation_alloc_from_heap (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8088: _dispatch_async_f_redirect (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D9B99: _T08Dispatch0A5QueueC5asyncyAA0A5GroupCSg5group_AA0A3QoSV3qosAA0A13WorkItemFlagsV5flagsyyXB7executetF (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40174E: main (in /home/jweiss/test)

full report:

$ swiftc test.swift &&  time valgrind --leak-check=full --show-leak-kinds=all ./test > /dev/null
==27516== Memcheck, a memory error detector
==27516== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==27516== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==27516== Command: ./test
==27516== 
==27516== Thread 3:
==27516== Syscall param epoll_ctl(event) points to uninitialised byte(s)
==27516==    at 0x5D7C97A: epoll_ctl (syscall-template.S:84)
==27516==    by 0x40D1023: _dispatch_timeout_program (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D0EDF: _dispatch_event_loop_timer_arm (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40CDF21: _dispatch_timers_program (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40CCE69: _dispatch_mgr_invoke (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40CCD1D: _dispatch_mgr_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8DF7: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516==  Address 0x4127c78 is on thread 3's stack
==27516==  in frame #&#8203;1, created by _dispatch_timeout_program (???:)
==27516== 
^C==27516== 
==27516== Process terminating with default action of signal 2 (SIGINT)
==27516==    at 0x604E825: futex_abstimed_wait_cancelable (futex-internal.h:205)
==27516==    by 0x604E825: do_futex_wait.constprop.3 (sem_waitcommon.c:111)
==27516==    by 0x604E8D3: __new_sem_wait_slow.constprop.0 (sem_waitcommon.c:181)
==27516==    by 0x604E979: sem_wait@@GLIBC_2.2.5 (sem_wait.c:29)
==27516==    by 0x40D16F5: _dispatch_sema4_wait (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40CA0F8: _dispatch_group_wait_slow (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40175F: main (in /home/jweiss/test)
==27516== 
==27516== HEAP SUMMARY:
==27516==     in use at exit: 905,290 bytes in 12,917 blocks
==27516==   total heap usage: 1,540,237 allocs, 1,527,320 frees, 90,513,020 bytes allocated
==27516== 
==27516== Thread 1:
==27516== 2 bytes in 1 blocks are still reachable in loss record 1 of 22
==27516==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x5D00489: strdup (strdup.c:42)
==27516==    by 0x40C2201: _dispatch_queue_create_with_target (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40E08AC: _T08Dispatch0A5QueueCACSS5label_AA0A3QoSV3qosAC10AttributesV10attributesAC20AutoreleaseFrequencyO011autoreleaseI0ACSg6targettcfcTf4gXxnngg_nTf4nnnnnnnnn_g (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D9873: _T08Dispatch0A5QueueCACSS5label_AA0A3QoSV3qosAC10AttributesV10attributesAC20AutoreleaseFrequencyO011autoreleaseI0ACSg6targettcfC (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x4015B5: main (in /home/jweiss/test)
==27516== 
==27516== 24 bytes in 1 blocks are still reachable in loss record 2 of 22
==27516==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x524B3C5: swift_slowAlloc (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libswiftCore.so)
==27516==    by 0x524B3FE: _swift_allocObject_ (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libswiftCore.so)
==27516==    by 0x40DBF3E: _T08Dispatch0A5GroupCACycfC (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x4014F6: main (in /home/jweiss/test)
==27516== 
==27516== 24 bytes in 1 blocks are still reachable in loss record 3 of 22
==27516==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x524B3C5: swift_slowAlloc (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libswiftCore.so)
==27516==    by 0x524B3FE: _swift_allocObject_ (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libswiftCore.so)
==27516==    by 0x40D9849: _T08Dispatch0A5QueueCACSS5label_AA0A3QoSV3qosAC10AttributesV10attributesAC20AutoreleaseFrequencyO011autoreleaseI0ACSg6targettcfC (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x4015B5: main (in /home/jweiss/test)
==27516== 
==27516== 64 bytes in 1 blocks are still reachable in loss record 4 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B7853: _dispatch_continuation_alloc_from_heap (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40CA9F6: dispatch_source_set_event_handler_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1DBD: _dispatch_workq_init_once (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 88 bytes in 1 blocks are still reachable in loss record 5 of 22
==27516==    at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x5252957: swift::Lazy<swift::MetadataCache<(anonymous namespace)::GenericCacheEntry> >::defaultInitCallback(void*) (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libswiftCore.so)
==27516==    by 0x604DA98: __pthread_once_slow (pthread_once.c:116)
==27516==    by 0x524F309: swift_getGenericMetadata (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libswiftCore.so)
==27516==    by 0x514BF2B: _T0s23_ContiguousArrayStorageCMa (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libswiftCore.so)
==27516==    by 0x40DD6CC: _T0s15ContiguousArrayV15reserveCapacityySiFs4Int8V_Tgq5 (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40DD51B: _T0SS11utf8CStrings15ContiguousArrayVys4Int8VGfgTfq4x_n (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40E0899: _T08Dispatch0A5QueueCACSS5label_AA0A3QoSV3qosAC10AttributesV10attributesAC20AutoreleaseFrequencyO011autoreleaseI0ACSg6targettcfcTf4gXxnngg_nTf4nnnnnnnnn_g (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D9873: _T08Dispatch0A5QueueCACSS5label_AA0A3QoSV3qosAC10AttributesV10attributesAC20AutoreleaseFrequencyO011autoreleaseI0ACSg6targettcfC (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x4015B5: main (in /home/jweiss/test)
==27516== 
==27516== 104 bytes in 1 blocks are still reachable in loss record 6 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B9F5F: _dispatch_calloc (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D06D4: _dispatch_unote_create (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D0861: _dispatch_source_timer_create (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40CA3A4: dispatch_source_create (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1D90: _dispatch_workq_init_once (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 112 bytes in 1 blocks are still reachable in loss record 7 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40BA011: _os_object_alloc_realized (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C9D81: dispatch_group_create (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40DBF46: _T08Dispatch0A5GroupCACycfC (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x4014F6: main (in /home/jweiss/test)
==27516== 
==27516== 120 bytes in 1 blocks are still reachable in loss record 8 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40BA011: _os_object_alloc_realized (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C2223: _dispatch_queue_create_with_target (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40E08AC: _T08Dispatch0A5QueueCACSS5label_AA0A3QoSV3qosAC10AttributesV10attributesAC20AutoreleaseFrequencyO011autoreleaseI0ACSg6targettcfcTf4gXxnngg_nTf4nnnnnnnnn_g (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D9873: _T08Dispatch0A5QueueCACSS5label_AA0A3QoSV3qosAC10AttributesV10attributesAC20AutoreleaseFrequencyO011autoreleaseI0ACSg6targettcfC (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x4015B5: main (in /home/jweiss/test)
==27516== 
==27516== 136 bytes in 1 blocks are still reachable in loss record 9 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40BA011: _os_object_alloc_realized (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40CA3C1: dispatch_source_create (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1D90: _dispatch_workq_init_once (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 320 bytes in 1 blocks are possibly lost in loss record 10 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40138A4: allocate_dtv (dl-tls.c:322)
==27516==    by 0x40138A4: _dl_allocate_tls (dl-tls.c:539)
==27516==    by 0x604726E: allocate_stack (allocatestack.c:588)
==27516==    by 0x604726E: pthread_create@@GLIBC_2.2.5 (pthread_create.c:539)
==27516==    by 0x40C5EA5: _dispatch_global_queue_poke_slow (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D9B99: _T08Dispatch0A5QueueC5asyncyAA0A5GroupCSg5group_AA0A3QoSV3qosAA0A13WorkItemFlagsV5flagsyyXB7executetF (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40174E: main (in /home/jweiss/test)
==27516== 
==27516== 320 bytes in 1 blocks are possibly lost in loss record 11 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40138A4: allocate_dtv (dl-tls.c:322)
==27516==    by 0x40138A4: _dl_allocate_tls (dl-tls.c:539)
==27516==    by 0x604726E: allocate_stack (allocatestack.c:588)
==27516==    by 0x604726E: pthread_create@@GLIBC_2.2.5 (pthread_create.c:539)
==27516==    by 0x40C5EA5: _dispatch_global_queue_poke_slow (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1223: _dispatch_epoll_init (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1125: _dispatch_event_loop_poke (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C2B54: _dispatch_queue_resume_finalize_activation (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516== 
==27516== 1,020 bytes in 1 blocks are still reachable in loss record 12 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B9F5F: _dispatch_calloc (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1CA1: _dispatch_workq_init_once (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 1,020 bytes in 1 blocks are still reachable in loss record 13 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B9F5F: _dispatch_calloc (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1CCB: _dispatch_workq_init_once (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 1,020 bytes in 1 blocks are still reachable in loss record 14 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B9F5F: _dispatch_calloc (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1CF5: _dispatch_workq_init_once (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 1,020 bytes in 1 blocks are still reachable in loss record 15 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B9F5F: _dispatch_calloc (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1D1F: _dispatch_workq_init_once (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 1,020 bytes in 1 blocks are still reachable in loss record 16 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B9F5F: _dispatch_calloc (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1D49: _dispatch_workq_init_once (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 1,020 bytes in 1 blocks are still reachable in loss record 17 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B9F5F: _dispatch_calloc (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1D6C: _dispatch_workq_init_once (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C10ED: dispatch_once_f (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D1C0D: _dispatch_workq_worker_register (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8BC4: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 3,520 bytes in 11 blocks are possibly lost in loss record 18 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40138A4: allocate_dtv (dl-tls.c:322)
==27516==    by 0x40138A4: _dl_allocate_tls (dl-tls.c:539)
==27516==    by 0x604726E: allocate_stack (allocatestack.c:588)
==27516==    by 0x604726E: pthread_create@@GLIBC_2.2.5 (pthread_create.c:539)
==27516==    by 0x40C5EA5: _dispatch_global_queue_poke_slow (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8D9F: _dispatch_worker_thread (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x60466B9: start_thread (pthread_create.c:333)
==27516==    by 0x5D7C3DC: clone (clone.S:109)
==27516== 
==27516== 9,600 bytes in 200 blocks are still reachable in loss record 19 of 22
==27516==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40D2242: _Block_copy_internal (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x401701: main (in /home/jweiss/test)
==27516== 
==27516== 72,704 bytes in 1 blocks are still reachable in loss record 20 of 22
==27516==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x545DEFF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==27516==    by 0x40106B9: call_init.part.0 (dl-init.c:72)
==27516==    by 0x40107CA: call_init (dl-init.c:30)
==27516==    by 0x40107CA: _dl_init (dl-init.c:120)
==27516==    by 0x4000C69: ??? (in /lib/x86_64-linux-gnu/ld-2.23.so)
==27516== 
==27516== 406,016 bytes in 6,344 blocks are still reachable in loss record 21 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B7853: _dispatch_continuation_alloc_from_heap (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C4E5E: dispatch_group_async (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D9B99: _T08Dispatch0A5QueueC5asyncyAA0A5GroupCSg5group_AA0A3QoSV3qosAA0A13WorkItemFlagsV5flagsyyXB7executetF (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40174E: main (in /home/jweiss/test)
==27516== 
==27516== 406,016 bytes in 6,344 blocks are still reachable in loss record 22 of 22
==27516==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27516==    by 0x40B7853: _dispatch_continuation_alloc_from_heap (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40C8088: _dispatch_async_f_redirect (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40D9B99: _T08Dispatch0A5QueueC5asyncyAA0A5GroupCSg5group_AA0A3QoSV3qosAA0A13WorkItemFlagsV5flagsyyXB7executetF (in /usr/local/swift/swift-4.0-RELEASE-ubuntu16.04/usr/lib/swift/linux/libdispatch.so)
==27516==    by 0x40174E: main (in /home/jweiss/test)
==27516== 
==27516== LEAK SUMMARY:
==27516==    definitely lost: 0 bytes in 0 blocks
==27516==    indirectly lost: 0 bytes in 0 blocks
==27516==      possibly lost: 4,160 bytes in 13 blocks
==27516==    still reachable: 901,130 bytes in 12,904 blocks
==27516==         suppressed: 0 bytes in 0 blocks
==27516== 
==27516== For counts of detected and suppressed errors, rerun with: -v
==27516== Use --track-origins=yes to see where uninitialised values come from
==27516== ERROR SUMMARY: 38 errors from 4 contexts (suppressed: 0 from 0)
Killed

real    0m35.986s
user    0m35.944s
sys 0m3.852s

@belkadan
Copy link

It's possible the top-level references to q1 and g are keeping them alive. What happens if you wrap all the top-level code up in a function and then call that function?

@swift-ci
Copy link
Author

Comment by Kim Topley (JIRA)

This is an infinite loop running a function that dispatches work to a concurrent queue. At any given time, there will be blocks in flight and therefore allocated memory that hasn't yet been freed. The valgrind report was obtained when the process was sent a SIGINT signal, so I would expect there to be memory that hasn't yet been freed. Most of the entries in the report seem to be in this category as they are labeled as still reachable. The memory that is reported as possibly lost was allocated by libpthread.

A more convincing test would stop and release all references to the objects that it allocated. Its not clear to me from this report that there is a leak.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants