mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-06 07:37:21 +02:00
Fix issues found by Coverity, closes #206.
This commit is contained in:
parent
f6c68cd6de
commit
510a0a6ae2
@ -122,22 +122,29 @@ const char *get_gov_state(void)
|
|||||||
long length = ftell(f);
|
long length = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
||||||
char contents[length];
|
if (length == -1)
|
||||||
|
{
|
||||||
|
LOG_ERROR("Failed to seek file %s\n", gov);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char contents[length];
|
||||||
|
|
||||||
if (fread(contents, 1, (size_t)length, f) > 0) {
|
if (fread(contents, 1, (size_t)length, f) > 0) {
|
||||||
/* Files have a newline */
|
/* Files have a newline */
|
||||||
strtok(contents, "\n");
|
strtok(contents, "\n");
|
||||||
if (strlen(governor) > 0 && strncmp(governor, contents, 64) != 0) {
|
if (strlen(governor) > 0 && strncmp(governor, contents, 64) != 0) {
|
||||||
/* Don't handle the mixed case, this shouldn't ever happen
|
/* Don't handle the mixed case, this shouldn't ever happen
|
||||||
* But it is a clear sign we shouldn't carry on */
|
* But it is a clear sign we shouldn't carry on */
|
||||||
LOG_ERROR("Governors malformed: got \"%s\", expected \"%s\"", contents, governor);
|
LOG_ERROR("Governors malformed: got \"%s\", expected \"%s\"", contents, governor);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return "malformed";
|
return "malformed";
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(governor, contents, sizeof(governor) - 1);
|
||||||
|
} else {
|
||||||
|
LOG_ERROR("Failed to read contents of %s\n", gov);
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(governor, contents, sizeof(governor) - 1);
|
|
||||||
} else {
|
|
||||||
LOG_ERROR("Failed to read contents of %s\n", gov);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
@ -224,7 +224,8 @@ char *game_mode_resolve_wine_preloader(const char *exe, const pid_t pid)
|
|||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
error_cleanup:
|
error_cleanup:
|
||||||
game_mode_close_proc(proc_fd);
|
if (proc_fd != INVALID_PROCFD)
|
||||||
|
game_mode_close_proc(proc_fd);
|
||||||
free(wineprefix);
|
free(wineprefix);
|
||||||
return wine_exe;
|
return wine_exe;
|
||||||
|
|
||||||
|
@ -132,11 +132,19 @@ static void daemonize(const char *name)
|
|||||||
/* replace standard file descriptors by /dev/null */
|
/* replace standard file descriptors by /dev/null */
|
||||||
int devnull_r = open("/dev/null", O_RDONLY);
|
int devnull_r = open("/dev/null", O_RDONLY);
|
||||||
int devnull_w = open("/dev/null", O_WRONLY);
|
int devnull_w = open("/dev/null", O_WRONLY);
|
||||||
dup2(devnull_r, STDIN_FILENO);
|
|
||||||
dup2(devnull_w, STDOUT_FILENO);
|
if (devnull_r == -1 || devnull_w == -1)
|
||||||
dup2(devnull_w, STDERR_FILENO);
|
{
|
||||||
close(devnull_r);
|
LOG_ERROR("Failed to redirect standard input and output to /dev/null\n");
|
||||||
close(devnull_w);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dup2(devnull_r, STDIN_FILENO);
|
||||||
|
dup2(devnull_w, STDOUT_FILENO);
|
||||||
|
dup2(devnull_w, STDERR_FILENO);
|
||||||
|
close(devnull_r);
|
||||||
|
close(devnull_w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user