fix(query): fix pthread_create memleak in shell engine

TD-17791
This commit is contained in:
Ganlin Zhao 2022-08-22 15:22:49 +08:00
parent ca641a27c4
commit 70df538180
3 changed files with 14 additions and 4 deletions

View File

@ -95,6 +95,7 @@ typedef struct {
TAOS* conn;
TdThread pid;
tsem_t cancelSem;
bool exit;
#ifdef WEBSOCKET
WS_TAOS* ws_conn;
bool stop_query;

View File

@ -948,6 +948,10 @@ void shellCleanup(void *arg) { taosResetTerminalMode(); }
void *shellCancelHandler(void *arg) {
setThreadName("shellCancelHandler");
while (1) {
if (shell.exit == true) {
break;
}
if (tsem_wait(&shell.cancelSem) != 0) {
taosMsleep(10);
continue;
@ -1079,7 +1083,12 @@ int32_t shellExecute() {
taosThreadCreate(&shell.pid, NULL, shellThreadLoop, NULL);
taosThreadJoin(shell.pid, NULL);
taosThreadClear(&shell.pid);
if (shell.exit) {
tsem_post(&shell.cancelSem);
break;
}
}
taosThreadJoin(spid, NULL);
shellCleanupHistory();
return 0;

View File

@ -157,6 +157,6 @@ void shellExit() {
taos_close(shell.conn);
shell.conn = NULL;
}
shell.exit = true;
taos_cleanup();
exit(EXIT_FAILURE);
}