提交 be142916 编写于 作者: 陶建辉(Jeff)'s avatar 陶建辉(Jeff)

TD-1772

pThreadObj is freed when thread exits
上级 5c6bde88
...@@ -190,6 +190,7 @@ void dnodeFreeVnodeWqueue(void *wqueue) { ...@@ -190,6 +190,7 @@ void dnodeFreeVnodeWqueue(void *wqueue) {
void dnodeSendRpcVnodeWriteRsp(void *pVnode, void *param, int32_t code) { void dnodeSendRpcVnodeWriteRsp(void *pVnode, void *param, int32_t code) {
SWriteMsg *pWrite = (SWriteMsg *)param; SWriteMsg *pWrite = (SWriteMsg *)param;
if (pWrite == NULL) return;
if (code < 0) pWrite->code = code; if (code < 0) pWrite->code = code;
int32_t count = atomic_add_fetch_32(&pWrite->processedCount, 1); int32_t count = atomic_add_fetch_32(&pWrite->processedCount, 1);
......
...@@ -174,6 +174,10 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { ...@@ -174,6 +174,10 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) {
pThreadObj->stop = true; pThreadObj->stop = true;
eventfd_t fd = -1; eventfd_t fd = -1;
// save thread and pollFd into local variable since pThreadObj will be freed when thread exits
pthread_t thread = pThreadObj->thread;
int pollFd = pThreadObj->pollFd;
if (taosComparePthread(pThreadObj->thread, pthread_self())) { if (taosComparePthread(pThreadObj->thread, pthread_self())) {
pthread_detach(pthread_self()); pthread_detach(pthread_self());
return; return;
...@@ -196,8 +200,9 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { ...@@ -196,8 +200,9 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) {
} }
} }
if (taosCheckPthreadValid(pThreadObj->thread) && pThreadObj->pollFd >= 0) { // at this step, pThreadObj may have been released
pthread_join(pThreadObj->thread, NULL); if (taosCheckPthreadValid(thread) && pollFd >= 0) {
pthread_join(thread, NULL);
} }
if (fd != -1) taosCloseSocket(fd); if (fd != -1) taosCloseSocket(fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册