diff --git a/daemon/daemon_config.c b/daemon/daemon_config.c index 675c195..23e0e76 100644 --- a/daemon/daemon_config.c +++ b/daemon/daemon_config.c @@ -362,6 +362,7 @@ static void load_config_files(GameModeConfig *self) if (error) { LOG_MSG("Failed to parse config file - error on line %d!\n", error); } + fclose(f); } free(path); } diff --git a/daemon/governors-query.c b/daemon/governors-query.c index 9e0af0f..9d483c0 100644 --- a/daemon/governors-query.c +++ b/daemon/governors-query.c @@ -133,6 +133,7 @@ const char *get_gov_state(void) /* Don't handle the mixed case, this shouldn't ever happen * But it is a clear sign we shouldn't carry on */ LOG_ERROR("Governors malformed: got \"%s\", expected \"%s\"", contents, governor); + fclose(f); return "malformed"; } diff --git a/daemon/gpu-control.c b/daemon/gpu-control.c index 147cdd1..a2699c0 100644 --- a/daemon/gpu-control.c +++ b/daemon/gpu-control.c @@ -50,7 +50,10 @@ enum GPUVendor gamemode_get_gpu_vendor(long device) return Vendor_Invalid; } char buff[64]; - if (fgets(buff, 64, file) != NULL) { + bool got_line = fgets(buff, 64, file) != NULL; + fclose(file); + + if (got_line) { vendor = strtol(buff, NULL, 0); } else { LOG_ERROR("Coudn't read contents of file %s, will not apply optimisations!\n", path); diff --git a/daemon/gpuclockctl.c b/daemon/gpuclockctl.c index 8598a9f..873ab54 100644 --- a/daemon/gpuclockctl.c +++ b/daemon/gpuclockctl.c @@ -289,21 +289,27 @@ static int get_gpu_state_amd(struct GameModeGPUInfo *info) return -1; } + int ret = 0; + char buff[CONFIG_VALUE_MAX] = { 0 }; if (!fgets(buff, CONFIG_VALUE_MAX, file)) { LOG_ERROR("Could not read file %s (%s)!\n", path, strerror(errno)); - return -1; + ret = -1; } if (fclose(file) != 0) { LOG_ERROR("Could not close %s after reading (%s)!\n", path, strerror(errno)); - return -1; + ret = -1; } - /* Copy in the value from the file */ - strncpy(info->amd_performance_level, buff, CONFIG_VALUE_MAX - 1); - info->amd_performance_level[CONFIG_VALUE_MAX - 1] = '\0'; - return 0; + if( ret == 0 ) + { + /* Copy in the value from the file */ + strncpy(info->amd_performance_level, buff, CONFIG_VALUE_MAX - 1); + info->amd_performance_level[CONFIG_VALUE_MAX - 1] = '\0'; + } + + return ret; } /* @@ -320,17 +326,19 @@ static int set_gpu_state_amd_file(const char *filename, long device, const char return -1; } + int ret = 0; + if (fprintf(file, "%s", value) < 0) { LOG_ERROR("Could not write to %s (%s)!\n", path, strerror(errno)); - return -1; + ret = -1; } if (fclose(file) != 0) { LOG_ERROR("Could not close %s after writing (%s)!\n", path, strerror(errno)); - return -1; + ret = -1; } - return 0; + return ret; } /**