Fix issues found by Coverity, closes #206.

This commit is contained in:
Ahsan Fayaz 2020-07-17 18:55:00 +01:00
parent f6c68cd6de
commit 510a0a6ae2
3 changed files with 36 additions and 20 deletions

View File

@ -122,6 +122,12 @@ const char *get_gov_state(void)
long length = ftell(f); long length = ftell(f);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
if (length == -1)
{
LOG_ERROR("Failed to seek file %s\n", gov);
}
else
{
char contents[length]; char contents[length];
if (fread(contents, 1, (size_t)length, f) > 0) { if (fread(contents, 1, (size_t)length, f) > 0) {
@ -139,6 +145,7 @@ const char *get_gov_state(void)
} else { } else {
LOG_ERROR("Failed to read contents of %s\n", gov); LOG_ERROR("Failed to read contents of %s\n", gov);
} }
}
fclose(f); fclose(f);
} }

View File

@ -224,6 +224,7 @@ char *game_mode_resolve_wine_preloader(const char *exe, const pid_t pid)
goto fail; goto fail;
error_cleanup: error_cleanup:
if (proc_fd != INVALID_PROCFD)
game_mode_close_proc(proc_fd); game_mode_close_proc(proc_fd);
free(wineprefix); free(wineprefix);
return wine_exe; return wine_exe;

View File

@ -132,12 +132,20 @@ 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);
if (devnull_r == -1 || devnull_w == -1)
{
LOG_ERROR("Failed to redirect standard input and output to /dev/null\n");
}
else
{
dup2(devnull_r, STDIN_FILENO); dup2(devnull_r, STDIN_FILENO);
dup2(devnull_w, STDOUT_FILENO); dup2(devnull_w, STDOUT_FILENO);
dup2(devnull_w, STDERR_FILENO); dup2(devnull_w, STDERR_FILENO);
close(devnull_r); close(devnull_r);
close(devnull_w); close(devnull_w);
} }
}
/** /**
* Main bootstrap entry into gamemoded * Main bootstrap entry into gamemoded