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

#include <sys/event.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <imsg.h>

#include "dnsfoo.h"
#include "config.h"
#include "unbound_update.h"

#define MAX_NAME_SERVERS 5

void
unbound_update_dispatch(struct unbound_update_msg *msg) {
	char *params[MAX_NAME_SERVERS + 4]; /* unbound-control, forward_{add, remove}, '.', final NULL */
	char *p, **srv;
	int numns = 0;
	pid_t child;

	memset(params, 0, sizeof (params));
	params[0] = "unbound-control";
	if (msg->nslen > 0) {
		params[1] = "forward_add";
		params[2] = ".";
		srv = &params[3];
		p = msg->ns;
		while ((numns < MAX_NAME_SERVERS) && (msg->nslen > 0)) {
			if ((asprintf(&srv[numns++], "%s", p)) == -1)
				err(1, "asprintf");
			msg->nslen -= strlen(p) + 1;
			p += strlen(p) + 1;
		}
	} else {
		params[1] = "forward_remove";
		params[2] = ".";
		srv = &params[3];
	}

	switch ((child = fork())) {
		case -1:
			err(1, "fork");
			break;
		case 0:
			fclose(stdout); /* Prevent noise from unbound-control */
			execvp("unbound-control", params);
			err(1, "execvp");
			break;
		default:
			if (waitpid(child, NULL, 0) < 0)
				err(1, "waitpid");
	}
<commit_msg>Small cleanup, plug memory leak in unbound updater<commit_after>#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sys/event.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <imsg.h>

#include "dnsfoo.h"
#include "config.h"
#include "unbound_update.h"

#define MAX_NAME_SERVERS 5

void
unbound_update_dispatch(struct unbound_update_msg *msg) {
	char *params[MAX_NAME_SERVERS + 4]; /* unbound-control, forward_{add, remove}, '.', final NULL */
	char *p, **srv;
	int numns = 0;
	pid_t child;

	memset(params, 0, sizeof (params));
	params[0] = "unbound-control";
	params[1] = "forward_remove";
	params[2] = ".";
	if (msg->nslen > 0) {
		size_t nslen = msg->nslen;
		params[1] = "forward_add";
		srv = &params[3];
		p = msg->ns;
		while ((numns < MAX_NAME_SERVERS) && (nslen > 0)) {
			if ((asprintf(&srv[numns++], "%s", p)) == -1)
				err(1, "asprintf");
			nslen -= strlen(p) + 1;
			p += strlen(p) + 1;
		}
	}

	switch ((child = fork())) {
		case -1:
			err(1, "fork");
			break;
		case 0:
			fclose(stdout); /* Prevent noise from unbound-control */
			execvp("unbound-control", params);
			err(1, "execvp");
			break;
		default:
			if (waitpid(child, NULL, 0) < 0)
				err(1, "waitpid");
	}

{'fraction_non_alphanumeric': 0.20031987205117952, 'fraction_numerical': 0.018392642942822873, 'mean_word_length': 3.7748091603053435, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 32, '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': '2592773', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1036, 'n_words': 236}