diff --git a/src/main.c b/src/main.c index 226c926ce2..2018b00f32 100644 --- a/src/main.c +++ b/src/main.c @@ -310,6 +310,7 @@ int umain(int argc, char* argv[]) { int main(int argc, char* argv[]) { #endif jq_state *jq = NULL; + jq_util_input_state *input_state = NULL; int ret = JQ_OK_NO_OUTPUT; int compiled = 0; int parser_flags = 0; @@ -336,7 +337,7 @@ int main(int argc, char* argv[]) { jq = jq_init(); if (jq == NULL) { - perror("malloc"); + perror("jq_init"); ret = JQ_ERROR_SYSTEM; goto out; } @@ -344,7 +345,12 @@ int main(int argc, char* argv[]) { int dumpopts = JV_PRINT_INDENT_FLAGS(2); const char* program = 0; - jq_util_input_state *input_state = jq_util_input_init(NULL, NULL); // XXX add err_cb + input_state = jq_util_input_init(NULL, NULL); // XXX add err_cb + if (input_state == NULL) { + perror("jq_util_input_init"); + ret = JQ_ERROR_SYSTEM; + goto out; + } int further_args_are_strings = 0; int further_args_are_json = 0; diff --git a/src/util.c b/src/util.c index 2f961e3c81..a78c4849af 100644 --- a/src/util.c +++ b/src/util.c @@ -226,10 +226,12 @@ jq_util_input_state *jq_util_input_init(jq_util_msg_cb err_cb, void *err_cb_data err_cb_data = stderr; } jq_util_input_state *new_state = jv_mem_calloc(1, sizeof(*new_state)); - new_state->err_cb = err_cb; - new_state->err_cb_data = err_cb_data; - new_state->slurped = jv_invalid(); - new_state->current_filename = jv_invalid(); + if(new_state) { + new_state->err_cb = err_cb; + new_state->err_cb_data = err_cb_data; + new_state->slurped = jv_invalid(); + new_state->current_filename = jv_invalid(); + } return new_state; }