fix(query): fix pthread_create memleak in shell engine
TD-17791
This commit is contained in:
parent
ca641a27c4
commit
70df538180
|
@ -95,6 +95,7 @@ typedef struct {
|
||||||
TAOS* conn;
|
TAOS* conn;
|
||||||
TdThread pid;
|
TdThread pid;
|
||||||
tsem_t cancelSem;
|
tsem_t cancelSem;
|
||||||
|
bool exit;
|
||||||
#ifdef WEBSOCKET
|
#ifdef WEBSOCKET
|
||||||
WS_TAOS* ws_conn;
|
WS_TAOS* ws_conn;
|
||||||
bool stop_query;
|
bool stop_query;
|
||||||
|
|
|
@ -948,6 +948,10 @@ void shellCleanup(void *arg) { taosResetTerminalMode(); }
|
||||||
void *shellCancelHandler(void *arg) {
|
void *shellCancelHandler(void *arg) {
|
||||||
setThreadName("shellCancelHandler");
|
setThreadName("shellCancelHandler");
|
||||||
while (1) {
|
while (1) {
|
||||||
|
if (shell.exit == true) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (tsem_wait(&shell.cancelSem) != 0) {
|
if (tsem_wait(&shell.cancelSem) != 0) {
|
||||||
taosMsleep(10);
|
taosMsleep(10);
|
||||||
continue;
|
continue;
|
||||||
|
@ -961,7 +965,7 @@ void *shellCancelHandler(void *arg) {
|
||||||
taos_kill_query(shell.conn);
|
taos_kill_query(shell.conn);
|
||||||
#ifdef WEBSOCKET
|
#ifdef WEBSOCKET
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
printf("\n%s", shell.info.promptHeader);
|
printf("\n%s", shell.info.promptHeader);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1009,7 +1013,7 @@ int32_t shellExecute() {
|
||||||
if (shell.args.restful || shell.args.cloud) {
|
if (shell.args.restful || shell.args.cloud) {
|
||||||
if (shell_conn_ws_server(1)) {
|
if (shell_conn_ws_server(1)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
if (shell.args.auth == NULL) {
|
if (shell.args.auth == NULL) {
|
||||||
|
@ -1043,7 +1047,7 @@ int32_t shellExecute() {
|
||||||
if (shell.args.restful || shell.args.cloud) {
|
if (shell.args.restful || shell.args.cloud) {
|
||||||
ws_close(shell.ws_conn);
|
ws_close(shell.ws_conn);
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
taos_close(shell.conn);
|
taos_close(shell.conn);
|
||||||
#ifdef WEBSOCKET
|
#ifdef WEBSOCKET
|
||||||
}
|
}
|
||||||
|
@ -1079,7 +1083,12 @@ int32_t shellExecute() {
|
||||||
taosThreadCreate(&shell.pid, NULL, shellThreadLoop, NULL);
|
taosThreadCreate(&shell.pid, NULL, shellThreadLoop, NULL);
|
||||||
taosThreadJoin(shell.pid, NULL);
|
taosThreadJoin(shell.pid, NULL);
|
||||||
taosThreadClear(&shell.pid);
|
taosThreadClear(&shell.pid);
|
||||||
|
if (shell.exit) {
|
||||||
|
tsem_post(&shell.cancelSem);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
taosThreadJoin(spid, NULL);
|
||||||
|
|
||||||
shellCleanupHistory();
|
shellCleanupHistory();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -157,6 +157,6 @@ void shellExit() {
|
||||||
taos_close(shell.conn);
|
taos_close(shell.conn);
|
||||||
shell.conn = NULL;
|
shell.conn = NULL;
|
||||||
}
|
}
|
||||||
|
shell.exit = true;
|
||||||
taos_cleanup();
|
taos_cleanup();
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue