diff --git a/src/combine.cc b/src/combine.cc index 65189f41..2fa5e55d 100644 --- a/src/combine.cc +++ b/src/combine.cc @@ -40,7 +40,7 @@ struct combine_data { char *right; }; -void parse_combine_arg(struct text_object *obj, const char *arg, void *free_at_crash) +void parse_combine_arg(struct text_object *obj, const char *arg) { struct combine_data *cd; unsigned int i,j; @@ -89,7 +89,7 @@ void parse_combine_arg(struct text_object *obj, const char *arg, void *free_at_c extract_variable_text_internal(obj->sub->sub, cd->right); obj->data.opaque = cd; } else { - CRIT_ERR(obj, free_at_crash, "combine needs arguments: "); + throw combine_needs_2_args_error(); } } diff --git a/src/combine.h b/src/combine.h index 1eb0a0d4..5e95e9de 100644 --- a/src/combine.h +++ b/src/combine.h @@ -30,7 +30,7 @@ #ifndef _COMBINE_H #define _COMBINE_H -void parse_combine_arg(struct text_object *, const char *, void *); +void parse_combine_arg(struct text_object *, const char *); void print_combine(struct text_object *, char *, int); void free_combine(struct text_object *); diff --git a/src/conky.cc b/src/conky.cc index a4601e4e..7a972537 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -4495,6 +4495,11 @@ int main(int argc, char **argv) } catch(fork_throw &e) { return EXIT_SUCCESS; } catch(unknown_arg_throw &e) { return EXIT_FAILURE; } + catch(obj_create_error &e) { + std::cerr << e.what() << std::endl; + clean_up(NULL, NULL); + return EXIT_FAILURE; + } #ifdef BUILD_CURL curl_global_cleanup(); diff --git a/src/core.cc b/src/core.cc index 866840f9..8a1ce834 100644 --- a/src/core.cc +++ b/src/core.cc @@ -1726,8 +1726,14 @@ struct text_object *construct_text_object(char *s, const char *arg, long parse_scroll_arg(obj, arg, free_at_crash, s); obj->callbacks.print = &print_scroll; obj->callbacks.free = &free_scroll; - END OBJ_ARG(combine, 0, "combine needs arguments: ") - parse_combine_arg(obj, arg, free_at_crash); + END OBJ(combine, 0) + try { + parse_combine_arg(obj, arg); + } + catch(combine_needs_2_args_error &e) { + free(obj); + throw obj_create_error(e.what()); + } obj->callbacks.print = &print_combine; obj->callbacks.free = &free_combine; #ifdef BUILD_NVIDIA @@ -1955,8 +1961,15 @@ int extract_variable_text_internal(struct text_object *retval, const char *const tmp_p++; } - obj = construct_text_object(buf, arg, + try { + obj = construct_text_object(buf, arg, line, &ifblock_opaque, orig_p); + } + catch(obj_create_error &e) { + free(buf); + free(orig_p); + throw e; + } if (obj != NULL) { append_object(retval, obj); } diff --git a/src/logging.h b/src/logging.h index 6821800f..6c01fc03 100644 --- a/src/logging.h +++ b/src/logging.h @@ -47,6 +47,18 @@ public: unknown_arg_throw(const std::string &msg) : std::runtime_error(msg) {} }; +class combine_needs_2_args_error : public std::runtime_error { +public: + combine_needs_2_args_error() : std::runtime_error("combine needs arguments: ") {} + combine_needs_2_args_error(const std::string &msg) : std::runtime_error(msg) {} +}; + +class obj_create_error : public std::runtime_error { +public: + obj_create_error() : std::runtime_error("Failed to create object") {} + obj_create_error(const std::string &msg) : std::runtime_error(msg) {} +}; + void clean_up(void *memtofree1, void* memtofree2); void clean_up_without_threads(void *memtofree1, void* memtofree2);