Memory Leak in CUDTUnited::listen
Brought to you by:
lilyco
If you call listen more than one on a socket (like if an error occurs), you will leak memory on these lines:
s->m_pQueuedSockets = new set<UDTSOCKET>;
s->m_pAcceptSockets = new set<UDTSOCKET>;
Perhaps a NULL check is just needed around them to avoid re-allocating them.
Also in the catch that follows it only cleans up the m_pQueueSockets, not the m_pAcceptSockets, which seems incorrect to me also.
This is a general problem that APIs such as bind, listen, and connect cannot be called concurrently. The app can call listen more than once, but not the same time. Call listen the 2nd time will return without doing anything because the socket is already in the listening state.
I added mutex to prevent multiple threads from calling listen at the same time.
Thanks for the bug report.
Sorry I wasn't clear. This isn't a concurrent call. If I call listen() once and it fails, then I call it again (in the same thread on the same socket), it will leak memory because it will realloc those sets.