<commit_before>#define CATCH_CONFIG_MAIN

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

#include "catch.hpp"

#include <cserial.h>

#ifdef _WIN32
#define snprintf _snprintf_s
#define sprintf sprintf_s
#define strcat strcat_s
#endif

TEST_CASE("Loopback send/receive", "[tx][rx][loopback]")
{
	struct cserial_port txPort, rxPort;
	struct cserial_port_conf conf = {
		conf.baud = 19200,
		conf.parity = PARITY_NONE,
		conf.csize = 8,
		conf.stopbits = 1,
	};
	char *txDev, *rxDev;
	char tx[32], rx[32];
	int txLen;
	int ret;

	memset(tx, 0, sizeof(tx));
	memset(rx, 0, sizeof(rx));

	snprintf(tx, sizeof(tx), "Erich");

	/* Get the device file to transmit data out. */
	txDev = getenv("CSERIAL_TX");
	INFO("transmitting using: " << txDev);
	REQUIRE(txDev != 0);

	/* Get the device file to receive data in. */
	rxDev = getenv("CSERIAL_RX");
	INFO("receiving using: " << rxDev);
	REQUIRE(rxDev != 0);

	ret = cserial_open(&txPort, &conf, txDev);
	REQUIRE(ret == 0);
	ret = cserial_open(&rxPort, &conf, rxDev);
	REQUIRE(ret == 0);

	txLen = strlen(tx);
	ret = cserial_write(&txPort, tx, txLen);
	REQUIRE(ret == txLen);

	ret = cserial_read(&rxPort, rx, sizeof(rx));
	/* We should receive everything we transmitted. */
	REQUIRE(ret == txLen);

	ret = cserial_close(&txPort);
	ret = cserial_close(&rxPort);
	REQUIRE(ret == 0);
}
<commit_msg>Fixed memory leak in unit test.<commit_after>#define CATCH_CONFIG_MAIN

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

#include "catch.hpp"

#include <cserial.h>

#ifdef _WIN32
#define snprintf _snprintf_s
#define sprintf sprintf_s
#define strcat strcat_s
#endif

TEST_CASE("Loopback send/receive", "[tx][rx][loopback]")
{
	struct cserial_port txPort, rxPort;
	struct cserial_port_conf conf = {
		conf.baud = 19200,
		conf.parity = PARITY_NONE,
		conf.csize = 8,
		conf.stopbits = 1,
	};
	char *txDev, *rxDev;
	char tx[32], rx[32];
	int txLen;
	int ret;

	memset(tx, 0, sizeof(tx));
	memset(rx, 0, sizeof(rx));

	snprintf(tx, sizeof(tx), "Erich");

	/* Get the device file to transmit data out. */
	txDev = getenv("CSERIAL_TX");
	INFO("transmitting using: " << txDev);
	REQUIRE(txDev != 0);

	/* Get the device file to receive data in. */
	rxDev = getenv("CSERIAL_RX");
	INFO("receiving using: " << rxDev);
	REQUIRE(rxDev != 0);

	ret = cserial_open(&txPort, &conf, txDev);
	REQUIRE(ret == 0);
	ret = cserial_open(&rxPort, &conf, rxDev);
	REQUIRE(ret == 0);

	txLen = strlen(tx);
	ret = cserial_write(&txPort, tx, txLen);
	REQUIRE(ret == txLen);

	ret = cserial_read(&rxPort, rx, sizeof(rx));
	/* We should receive everything we transmitted. */
	REQUIRE(ret == txLen);

	ret = cserial_close(&txPort);
	ret = cserial_close(&rxPort);
	REQUIRE(ret == 0);

	free(txPort.device);
	free(rxPort.device);
}

{'fraction_non_alphanumeric': 0.16342269555637165, 'fraction_numerical': 0.014689680499449137, 'mean_word_length': 4.698744769874477, 'pattern_counts': {'":': 0, '<': 17, '<?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': '6024952', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1073, 'n_words': 261}