Skip to content

Commit 08029d2

Browse files
Marjolein Verkoutershaoguangleo
Marjolein Verkouter
authored andcommitted
maybe fix issue jive-vlbi#24 (SIGSEGV)
Using the coredump at On was able to trace the SIGSEGV *happening in the garbage collector thread* that the UDT library starts (!): 6 0x000055e8617dd78e in CSndBuffer::~CSndBuffer (this=0x7f8e7c0021a0, __in_chrg=<optimized out>) at /usr/local/src/jive5ab.git/libudt5ab/buffer.cpp:101 7 0x000055e8617e208b in CUDT::~CUDT (this=0x55e8652c9780, __in_chrg=<optimized out>) at /usr/local/src/jive5ab.git/libudt5ab/core.cpp:195 8 0x000055e8617cab58 in CUDTSocket::~CUDTSocket (this=0x55e8652c9650, __in_chrg=<optimized out>) at /usr/local/src/jive5ab.git/libudt5ab/api.cpp:99 so it's likely that ~CSndBuffer() is being executed from different threads and the d'tor has no protection at all against that. It's a probable cause for sigsegv'ing so added a mutex (on non-Win32 systems) to see if that fixes the issue reported
1 parent 3ff293e commit 08029d2

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

libudt5ab/buffer.cpp

+32-22
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,38 @@ m_iCount(0)
9393

9494
CSndBuffer::~CSndBuffer()
9595
{
96-
Block* pb = m_pBlock->m_pNext;
97-
while (pb != m_pBlock)
98-
{
99-
Block* temp = pb;
100-
pb = pb->m_pNext;
101-
delete temp;
102-
}
103-
delete m_pBlock;
104-
105-
while (m_pBuffer != NULL)
106-
{
107-
Buffer* temp = m_pBuffer;
108-
m_pBuffer = m_pBuffer->m_pNext;
109-
delete [] temp->m_pcData;
110-
delete temp;
111-
}
112-
113-
#ifndef WIN32
114-
pthread_mutex_destroy(&m_BufLock);
115-
#else
116-
CloseHandle(m_BufLock);
117-
#endif
96+
#ifndef WIN32
97+
pthread_mutex_t dtor_lock = PTHREAD_MUTEX_INITIALIZER;
98+
::pthread_mutex_lock( &dtor_lock );
99+
#endif
100+
101+
Block* pb = (m_pBlock != NULL ? m_pBlock->m_pNext : NULL);
102+
while (pb != m_pBlock)
103+
{
104+
Block* temp = pb;
105+
pb = pb->m_pNext;
106+
delete temp;
107+
}
108+
delete m_pBlock;
109+
m_pBlock = NULL;
110+
111+
while (m_pBuffer != NULL)
112+
{
113+
Buffer* temp = m_pBuffer;
114+
m_pBuffer = m_pBuffer->m_pNext;
115+
delete [] temp->m_pcData;
116+
delete temp;
117+
}
118+
119+
#ifndef WIN32
120+
pthread_mutex_destroy(&m_BufLock);
121+
#else
122+
CloseHandle(m_BufLock);
123+
#endif
124+
125+
#ifndef WIN32
126+
::pthread_mutex_unlock( &dtor_lock );
127+
#endif
118128
}
119129

120130
void CSndBuffer::addBuffer(const char* data, int len, int ttl, bool order)

0 commit comments

Comments
 (0)