diff --git a/src/include/json.h b/src/include/json.h index 6f6c1761..2ad78590 100644 --- a/src/include/json.h +++ b/src/include/json.h @@ -155,9 +155,14 @@ pgagroal_json_is_command_name_equals_to(cJSON* json, char* command_name); * when there is the need to print out the information * contained in a json object. * + * Since the JSON object will be invalidated, the method + * returns the status of the JSON command within it + * to be used. + * * @param json the json object to print + * @return the command status within the JSON object */ -void +int pgagroal_json_print_and_free_json_object(cJSON* json); /** diff --git a/src/libpgagroal/json.c b/src/libpgagroal/json.c index 3f50109f..766bcc51 100644 --- a/src/libpgagroal/json.c +++ b/src/libpgagroal/json.c @@ -260,9 +260,11 @@ pgagroal_json_get_command_object_status(cJSON* json) } -void +int pgagroal_json_print_and_free_json_object(cJSON* json) { + int status = pgagroal_json_command_object_exit_status(json); printf("%s\n", cJSON_Print(json)); cJSON_Delete(json); + return status; } diff --git a/src/libpgagroal/management.c b/src/libpgagroal/management.c index f624b3c1..789b6736 100644 --- a/src/libpgagroal/management.c +++ b/src/libpgagroal/management.c @@ -1812,8 +1812,7 @@ pgagroal_management_read_config_get(int socket, char* config_key, char* expected if (output_format == COMMAND_OUTPUT_FORMAT_JSON) { - pgagroal_json_print_and_free_json_object(json); - goto end; + return pgagroal_json_print_and_free_json_object(json); } // if here, print out in text format @@ -1829,7 +1828,6 @@ pgagroal_management_read_config_get(int socket, char* config_key, char* expected printf("%s\n", value->valuestring); } -end: return pgagroal_json_command_object_exit_status(json); error: