mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-06 07:37:21 +02:00
daemon: fix file descriptor leaks
This commit is contained in:
parent
618997f0b3
commit
d7394cbeb2
@ -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);
|
||||
}
|
||||
|
@ -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";
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user