From: Jasvinder Singh Date: Mon, 22 Jan 2018 15:15:04 +0000 (+0000) Subject: app/testpmd: fix allocation check in MTR parsing X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=0c36b7c4908865622a9eb8b1017eb96ba114e9e7;p=dpdk.git app/testpmd: fix allocation check in MTR parsing Malloc() function might return NULL due to insufficient space. Therefore, check for handling memory allocation failure is added. Coverity issue: 257039 Fixes: e63b50162aa3 ("app/testpmd: clean metering and policing commands") Signed-off-by: Jasvinder Singh --- diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c index 96a851b6f1..f908fb3520 100644 --- a/app/test-pmd/cmdline_mtr.c +++ b/app/test-pmd/cmdline_mtr.c @@ -86,6 +86,8 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table) /* Allocate memory for dscp table */ dscp_table = (enum rte_mtr_color *)malloc(MAX_DSCP_TABLE_ENTRIES * sizeof(enum rte_mtr_color)); + if (dscp_table == NULL) + return -1; while (1) { if (strcmp(token, "G") == 0 || @@ -105,8 +107,10 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table) break; token = strtok_r(str, PARSE_DELIMITER, &str); - if (token == NULL) + if (token == NULL) { + free(dscp_table); return -1; + } } return 0; }