From cf014abd96d123a2ce243b9663ab22c1b22c330e Mon Sep 17 00:00:00 2001 From: fang Date: Mon, 9 Dec 2019 13:09:32 +0800 Subject: [PATCH] solve some static check questions for shell/src/ --- src/kit/shell/src/shellEngine.c | 3 +++ src/kit/shell/src/shellLinux.c | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index c66f6f4be7..ed3b71bfcd 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -780,6 +780,7 @@ void source_file(TAOS *con, char *fptr) { if (wordexp(fptr, &full_path, 0) != 0) { fprintf(stderr, "ERROR: illegal file name\n"); + free(cmd); return; } @@ -788,6 +789,7 @@ void source_file(TAOS *con, char *fptr) { if (access(fname, R_OK) == -1) { fprintf(stderr, "ERROR: file %s is not readable\n", fptr); wordfree(&full_path); + free(cmd); return; } @@ -795,6 +797,7 @@ void source_file(TAOS *con, char *fptr) { if (f == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); wordfree(&full_path); + free(cmd); return; } diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index ad8bf6c5c3..2e2c44af1a 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -277,7 +277,10 @@ void *shellLoopQuery(void *arg) { pthread_cleanup_push(cleanup_handler, NULL); char *command = malloc(MAX_COMMAND_SIZE); - + if (command == NULL){ + tscError("failed to malloc command"); + return NULL; + } while (1) { // Read command from shell. @@ -286,10 +289,8 @@ void *shellLoopQuery(void *arg) { shellReadCommand(con, command); reset_terminal_mode(); - if (command != NULL) { - // Run the command - shellRunCommand(con, command); - } + // Run the command + shellRunCommand(con, command); } pthread_cleanup_pop(1);