From ecbceac3414bf851d166e8ce7dceaf1dae12bb08 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 9 Feb 2014 00:59:03 -0500 Subject: Fixed memory leaks and removed repeated code --- testing/experiment/group_chats_test1.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'testing/experiment/group_chats_test1.c') diff --git a/testing/experiment/group_chats_test1.c b/testing/experiment/group_chats_test1.c index a74f808a..fc10ab64 100644 --- a/testing/experiment/group_chats_test1.c +++ b/testing/experiment/group_chats_test1.c @@ -1,4 +1,6 @@ #include "../../toxcore/group_chats.h" +#include "../misc_tools.c" // hex_string_to_bin + #define NUM_CHATS 8 #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) @@ -54,19 +56,6 @@ void print_group(Group_Chat *chat) } } -unsigned char *hex_string_to_bin(char hex_string[]) -{ - size_t len = strlen(hex_string); - unsigned char *val = malloc(len); - char *pos = hex_string; - int i; - - for (i = 0; i < len; ++i, pos += 2) - sscanf(pos, "%2hhx", &val[i]); - - return val; -} - void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) { printf("%u: %s | %u\n", peer_number, message, length); @@ -95,8 +84,12 @@ int main(int argc, char *argv[]) * bootstrap_ip_port.ip.c[2] = 0; * bootstrap_ip_port.ip.c[3] = 1; */ bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); + + uint8_t *bootstrap_id = hex_string_to_bin(argv[3]); - chat_bootstrap(chat, bootstrap_ip_port, hex_string_to_bin(argv[3])); + chat_bootstrap(chat, bootstrap_ip_port, bootstrap_id); + + free(bootstrap_id); while (1) { -- cgit v1.2.3