check open file before close()

This commit is contained in:
4zv4l 2021-11-03 13:28:27 +01:00
parent e0d7d7ede1
commit 46661f64e7

View file

@ -666,9 +666,10 @@ void get_info()
#else #else
FILE *cpuinfo = popen("sysctl -a | egrep -i 'hw.model'", "r"); FILE *cpuinfo = popen("sysctl -a | egrep -i 'hw.model'", "r");
#endif #endif
FILE *host_model_info = fopen("/sys/devices/virtual/dmi/id/board_name", "r"); FILE *host_model_info = fopen("/sys/devices/virtual/dmi/id/board_name", "r"); // first try open the file
if (!host_model_info) if (!host_model_info) // if failed
if ((host_model_info = fopen("/sys/devices/virtual/dmi/id/product_name", "r")) != NULL) host_model_info = fopen("/sys/devices/virtual/dmi/id/product_name", "r"); // try open another file
if(host_model_info) // if one of the file could be open then close it
fclose(host_model_info); fclose(host_model_info);
#ifdef __WINDOWS__ #ifdef __WINDOWS__
host_model_info = popen("wmic computersystem get model", "r"); host_model_info = popen("wmic computersystem get model", "r");