<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cJSON.h"
#include "compiler.h"
#include "jet_config.h"
#include "peer.h"
#include "response.h"

int process_config(cJSON *json_rpc, const struct peer *p)
{
	int ret = 0;
	cJSON *id = cJSON_GetObjectItem(json_rpc, "id");
	if (likely(id != NULL)) {
		char *rendered;

		cJSON *response = create_boolean_success_response(id, TRUE);
		if (unlikely (response == NULL)) {
			return -1;
		}
		rendered = cJSON_PrintUnformatted(response);
		if (unlikely(rendered == NULL)) {
			fprintf(stderr, "Could not render JSON into a string!\n");
			ret = -1;
			goto render_error;
		}
		ret = send_message(p, rendered, strlen(rendered));
		if (likely(ret == 0)) {
			free(rendered);
		}
	render_error:
		cJSON_Delete(response);
	}
	return ret;
}
<commit_msg>Free the rendered JSON also in case of an error.<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cJSON.h"
#include "compiler.h"
#include "jet_config.h"
#include "peer.h"
#include "response.h"

int process_config(cJSON *json_rpc, const struct peer *p)
{
	int ret = 0;
	cJSON *id = cJSON_GetObjectItem(json_rpc, "id");
	if (likely(id != NULL)) {
		char *rendered;

		cJSON *response = create_boolean_success_response(id, TRUE);
		if (unlikely (response == NULL)) {
			return -1;
		}
		rendered = cJSON_PrintUnformatted(response);
		if (unlikely(rendered == NULL)) {
			fprintf(stderr, "Could not render JSON into a string!\n");
			ret = -1;
			goto render_error;
		}
		ret = send_message(p, rendered, strlen(rendered));
		free(rendered);
	render_error:
		cJSON_Delete(response);
	}
	return ret;
}

{'fraction_non_alphanumeric': 0.14794685990338163, 'fraction_numerical': 0.004227053140096618, 'mean_word_length': 4.486754966887418, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2699568', 'n_tokens_mistral': 658, 'n_tokens_neox': 605, 'n_words': 154}