Check for fgets() failure in addition to fopen() failure and take appropriate action. CC: Gil Rockah <gilr@xxxxxxxxxxxx> Signed-off-by: Jarod Wilson <jarod@xxxxxxxxxx> --- src/perftest_parameters.c | 5 ++++- src/perftest_resources.c | 5 ++++- src/raw_ethernet_resources.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/perftest_parameters.c b/src/perftest_parameters.c index e316143..32ebea9 100755 --- a/src/perftest_parameters.c +++ b/src/perftest_parameters.c @@ -147,7 +147,10 @@ static int get_cache_line_size() if (fp == NULL) { return DEF_CACHE_LINE_SIZE; } - fgets(line,10,fp); + if (fgets(line,10,fp) == NULL) { + fclose(fp); + return DEF_CACHE_LINE_SIZE; + } size = atoi(line); fclose(fp); } diff --git a/src/perftest_resources.c b/src/perftest_resources.c index 4dc0705..91c6d1e 100755 --- a/src/perftest_resources.c +++ b/src/perftest_resources.c @@ -230,7 +230,10 @@ static void get_cpu_stats(struct perftest_parameters *duration_param,int stat_in int index=0; fp = fopen(file_name, "r"); if (fp != NULL) { - fgets(line,100,fp); + if (fgets(line,100,fp) == NULL) { + fclose(fp); + return; + } compress_spaces(line,line); index=get_n_word_string(line,tmp,index,2); /* skip first word */ duration_param->cpu_util_data.ustat[stat_index-1] = atoll(tmp); diff --git a/src/raw_ethernet_resources.c b/src/raw_ethernet_resources.c index d087cab..22e1bab 100755 --- a/src/raw_ethernet_resources.c +++ b/src/raw_ethernet_resources.c @@ -69,7 +69,10 @@ int check_flow_steering_support(char *dev_name) fp = fopen(file_name, "r"); if (fp == NULL) return 0; - fgets(line,4,fp); + if (fgets(line,4,fp) == NULL) { + fclose(fp); + return 0; + } int val = atoi(line); if (val >= 0) { -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html