mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 08:25:59 +01:00
Fix memory leak
This commit is contained in:
parent
48cf3a22e0
commit
241d302b09
1 changed files with 34 additions and 13 deletions
|
@ -184,6 +184,7 @@ main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
g_option_context_free(context);
|
g_option_context_free(context);
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
set_log_level(loglevel);
|
set_log_level(loglevel);
|
||||||
|
|
||||||
#ifdef WITH_SYNCTEX
|
#ifdef WITH_SYNCTEX
|
||||||
|
@ -192,17 +193,20 @@ main(int argc, char* argv[])
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
girara_error("Too many arguments or missing filename while running with "
|
girara_error("Too many arguments or missing filename while running with "
|
||||||
"--synctex-forward");
|
"--synctex-forward");
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int ret = run_synctex_forward(synctex_fwd, argv[1], synctex_pid);
|
ret = run_synctex_forward(synctex_fwd, argv[1], synctex_pid);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
/* Instance found. */
|
/* Instance found. */
|
||||||
return 0;
|
ret = 0;
|
||||||
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
else if (ret < 0) {
|
else if (ret < 0) {
|
||||||
/* Error occurred. */
|
/* Error occurred. */
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
girara_debug("No instance found. Starting new one.");
|
girara_debug("No instance found. Starting new one.");
|
||||||
|
@ -213,7 +217,8 @@ main(int argc, char* argv[])
|
||||||
if (mode != NULL && g_strcmp0(mode, "presentation") != 0 &&
|
if (mode != NULL && g_strcmp0(mode, "presentation") != 0 &&
|
||||||
g_strcmp0(mode, "fullscreen") != 0) {
|
g_strcmp0(mode, "fullscreen") != 0) {
|
||||||
girara_error("Invalid argument for --mode: %s", mode);
|
girara_error("Invalid argument for --mode: %s", mode);
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* g_option_context_parse has some funny (documented) behavior:
|
/* g_option_context_parse has some funny (documented) behavior:
|
||||||
|
@ -235,13 +240,15 @@ main(int argc, char* argv[])
|
||||||
if (setsid() == -1) {
|
if (setsid() == -1) {
|
||||||
girara_error("Could not start new process group: %s",
|
girara_error("Could not start new process group: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (pid < 0) { /* error */
|
else if (pid < 0) { /* error */
|
||||||
girara_error("Could not fork: %s", strerror(errno));
|
girara_error("Could not fork: %s", strerror(errno));
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,16 +258,18 @@ main(int argc, char* argv[])
|
||||||
file_idx < file_idx_base + 1) {
|
file_idx < file_idx_base + 1) {
|
||||||
const pid_t pid = fork();
|
const pid_t pid = fork();
|
||||||
if (pid > 0) { /* parent */
|
if (pid > 0) { /* parent */
|
||||||
return 0;
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
else if (pid < 0) { /* error */
|
else if (pid < 0) { /* error */
|
||||||
girara_error("Could not fork: %s", strerror(errno));
|
girara_error("Could not fork: %s", strerror(errno));
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsid() == -1) {
|
if (setsid() == -1) {
|
||||||
girara_error("Could not start new process group: %s", strerror(errno));
|
girara_error("Could not start new process group: %s", strerror(errno));
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +281,8 @@ main(int argc, char* argv[])
|
||||||
plugin_path, argv, synctex_editor, embed);
|
plugin_path, argv, synctex_editor, embed);
|
||||||
if (zathura == NULL) {
|
if (zathura == NULL) {
|
||||||
girara_error("Could not initialize zathura.");
|
girara_error("Could not initialize zathura.");
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print version */
|
/* Print version */
|
||||||
|
@ -284,7 +294,7 @@ main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
zathura_free(zathura);
|
zathura_free(zathura);
|
||||||
|
|
||||||
return 0;
|
goto free_and_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open document if passed */
|
/* open document if passed */
|
||||||
|
@ -302,5 +312,16 @@ main(int argc, char* argv[])
|
||||||
/* free zathura */
|
/* free zathura */
|
||||||
zathura_free(zathura);
|
zathura_free(zathura);
|
||||||
|
|
||||||
return 0;
|
free_and_ret:
|
||||||
|
g_free(config_dir);
|
||||||
|
g_free(data_dir);
|
||||||
|
g_free(cache_dir);
|
||||||
|
g_free(plugin_path);
|
||||||
|
g_free(loglevel);
|
||||||
|
g_free(password);
|
||||||
|
g_free(synctex_editor);
|
||||||
|
g_free(synctex_fwd);
|
||||||
|
g_free(mode);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue