rtc::ThreadManager and Visual Leak Detector

121 views
Skip to first unread message

Elise Monaghan

unread,
Nov 24, 2021, 9:28:55 AM11/24/21
to discuss-webrtc
Visual Leak Detector seems to detect leaks in code simply upon creating a Win32Thread and then quitting. The following code:

    rtc::WinsockInitializer winsock_init;
    rtc::Win32SocketServer w32_ss;
    rtc::Win32Thread w32_thread(&w32_ss);
    rtc::InitializeSSL();
    rtc::CleanupSSL();


Produces the following leak:

---------- Block 9160 at 0x000000009AE8AEE0: 64 bytes ----------
  Leak Hash: 0xC0D7A6B5, Count: 1, Total 64 bytes
  Call Stack (TID 3520):
    ucrtbased.dll!malloc()
    d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\heap\new_scalar.cpp (35): my-app.exe!operator new() + 0xA bytes
    c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\xmemory0 (53): my-app.exe!std::_Default_allocate_traits::_Allocate()
    c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\xmemory0 (190): my-app.exe!std::_Allocate<16,std::_Default_allocate_traits,0>() + 0xA bytes
    my-app.exe!std::allocator<std::_Tree_node<std::pair<rtc::Thread * __ptr64 const,std::set<rtc::Thread * __ptr64,std::less<rtc::Thread * __ptr64>,std::allocator<rtc::Thread * __ptr64> > >,void * __ptr64> >::allocate() + 0x20 bytes
    my-app.exe!std::_Tree_comp_alloc<std::_Tmap_traits<rtc::Thread * __ptr64,std::set<rtc::Thread * __ptr64,std::less<rtc::Thread * __ptr64>,std::allocator<rtc::Thread * __ptr64> >,std::less<rtc::Thread * __ptr64>,std::allocator<std::pair<rtc::Thread * __ptr64 const,std() + 0x27 bytes
    my-app.exe!std::_Tree_comp_alloc<std::_Tmap_traits<rtc::Thread * __ptr64,std::set<rtc::Thread * __ptr64,std::less<rtc::Thread * __ptr64>,std::allocator<rtc::Thread * __ptr64> >,std::less<rtc::Thread * __ptr64>,std::allocator<std::pair<rtc::Thread * __ptr64 const,std() + 0x22 bytes
    my-app.exe!std::_Tree_comp_alloc<std::_Tmap_traits<rtc::Thread * __ptr64,std::set<rtc::Thread * __ptr64,std::less<rtc::Thread * __ptr64>,std::allocator<rtc::Thread * __ptr64> >,std::less<rtc::Thread * __ptr64>,std::allocator<std::pair<rtc::Thread * __ptr64 const,std() + 0x34 bytes
    my-app.exe!std::_Tree<std::_Tmap_traits<rtc::Thread * __ptr64,std::set<rtc::Thread * __ptr64,std::less<rtc::Thread * __ptr64>,std::allocator<rtc::Thread * __ptr64> >,std::less<rtc::Thread * __ptr64>,std::allocator<std::pair<rtc::Thread * __ptr64 const,std::set<rtc::() + 0x1D bytes
    my-app.exe!std::map<rtc::Thread * __ptr64,std::set<rtc::Thread * __ptr64,std::less<rtc::Thread * __ptr64>,std::allocator<rtc::Thread * __ptr64> >,std::less<rtc::Thread * __ptr64>,std::allocator<std::pair<rtc::Thread * __ptr64 const,std::set<rtc::Thread * __ptr64,std() + 0x18 bytes
    my-app.exe!rtc::ThreadManager::ThreadManager() + 0x45 bytes
    my-app.exe!rtc::ThreadManager::Instance() + 0x5F bytes
    my-app.exe!rtc::ThreadManager::Add() + 0xE bytes
    my-app.exe!rtc::Thread::DoInit() + 0x31 bytes
    my-app.exe!rtc::Thread::Thread() + 0x282 bytes
    my-app.exe!rtc::Thread::Thread() + 0x20 bytes
    my-app.exe!rtc::Win32Thread::Win32Thread() + 0x1D bytes


What am I missing? Is there some sort of specific cleanup required that I need to perform?

Thanks


James Inkster

unread,
Nov 25, 2021, 11:30:07 AM11/25/21
to discuss-webrtc
Hi Elise,
This is very intriguing -- my team has been chasing a "leak" that seems very similar, with no luck in tracking down the root cause. 
Have you a small standalone app that would reproduce this? 
Perhaps an official bug report should be submitted -- we've been resistant because we've assumed the problem was ours, and couldn't possibly be in the released webrtc code :)

Thanks,
james

Vitaly Ivanov

unread,
Nov 25, 2021, 8:46:29 PM11/25/21
to discuss...@googlegroups.com
Hi James,

By the looks of it, you can just take peerconnection_client and put the code into main() to get a repro case: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/examples/peerconnection/client/main.cc;l=73

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/e09e39cc-a872-4ad9-90ec-a4d314dcad9an%40googlegroups.com.

Vitaly Ivanov

unread,
Nov 27, 2021, 4:59:41 AM11/27/21
to discuss...@googlegroups.com

James Inkster

unread,
Nov 29, 2021, 12:29:29 PM11/29/21
to discuss-webrtc
I'm not actually using the Win32s classes, but still see a leak.

Do you see a leak without using the Win32 classes, Elise?

zhiguang zhang

unread,
Dec 4, 2021, 2:46:25 PM12/4/21
to discuss...@googlegroups.com
not sure but there is already some socket server threading code in the webrtc library, maybe that can be a reference


--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.

zhiguang zhang

unread,
Dec 4, 2021, 2:47:12 PM12/4/21
to discuss...@googlegroups.com
try to start from brass tax down to the DAC and any audio components you have plugged in, make sure your audio hardware path is isolated

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages