aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-23 08:39:15 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-23 09:11:51 +0200
commit96c9ed391270347c4c7036179fd2815f679ca7cf (patch)
tree8dac4bd431bf57a3391d0aeb802aa34704043b4b /src
parent8f73d303b96d35ccec9856fc0043a74c8800536b (diff)
Kill program on read failure or callback returning non-0 value, fix potential crash
Diffstat (limited to 'src')
-rw-r--r--src/Program.c13
-rw-r--r--src/QuickMedia.cpp8
2 files changed, 14 insertions, 7 deletions
diff --git a/src/Program.c b/src/Program.c
index fc80e5e..a82bcd2 100644
--- a/src/Program.c
+++ b/src/Program.c
@@ -74,14 +74,20 @@ int exec_program(const char **args, ProgramOutputCallback output_callback, void
int err = errno;
fprintf(stderr, "Failed to read from pipe to program %s, error: %s\n", args[0], strerror(err));
result = -err;
- goto cleanup;
+ break;
}
buffer[bytes_read] = '\0';
- if(output_callback && output_callback(buffer, bytes_read, userdata) != 0)
- break;
+ if(output_callback) {
+ result = output_callback(buffer, bytes_read, userdata);
+ if(result != 0)
+ break;
+ }
}
+ if(result != 0)
+ kill(read_program.pid, SIGTERM);
+
if(waitpid(read_program.pid, &status, 0) == -1) {
perror("waitpid failed");
result = -5;
@@ -105,7 +111,6 @@ int exec_program(const char **args, ProgramOutputCallback output_callback, void
}
fprintf(stderr, "), exit status %d\n", exit_status);
result = -exit_status;
- goto cleanup;
}
cleanup:
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 7840326..48d3689 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1059,9 +1059,11 @@ namespace QuickMedia {
} else {
page_loop(std::move(new_tabs));
tabs[selected_tab].page->on_navigate_to_page();
- const Json::Value &chapters_json = content_storage_json["chapters"];
- if(chapters_json.isObject())
- json_chapters = &chapters_json;
+ if(content_storage_json.isObject()) {
+ const Json::Value &chapters_json = content_storage_json["chapters"];
+ if(chapters_json.isObject())
+ json_chapters = &chapters_json;
+ }
}
} else {
// TODO: Show the exact cause of error (get error message from curl).