Menu

#22 Memory Leak in CUDTUnited::listen

open-fixed
nobody
None
5
2011-05-14
2011-05-12
No

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.

Discussion

  • Yunhong Gu

    Yunhong Gu - 2011-05-14

    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.

     
  • Yunhong Gu

    Yunhong Gu - 2011-05-14
    • status: open --> open-fixed
     
  • - 2011-05-16

    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.

     

Log in to post a comment.