Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#399] Fix segmentation fault in conf get JSON format #400

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/include/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
4 changes: 3 additions & 1 deletion src/libpgagroal/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 1 addition & 3 deletions src/libpgagroal/management.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
Loading