@@ -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);
}
@@ -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);
@@ -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) {
Check for fgets() failure in addition to fopen() failure and take appropriate action. CC: Gil Rockah <gilr@mellanox.com> Signed-off-by: Jarod Wilson <jarod@redhat.com> --- src/perftest_parameters.c | 5 ++++- src/perftest_resources.c | 5 ++++- src/raw_ethernet_resources.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-)