diff options
author | Maxim Biro <nurupo.contributions@gmail.com> | 2014-02-09 00:59:03 -0500 |
---|---|---|
committer | Maxim Biro <nurupo.contributions@gmail.com> | 2014-02-09 02:01:04 -0500 |
commit | ecbceac3414bf851d166e8ce7dceaf1dae12bb08 (patch) | |
tree | 897b4adcb52ec6c88c24673bfb5855c0d5a3e427 /testing/experiment | |
parent | 5fad72b910fde1bf66fecf7728ac73354ab23a3b (diff) |
Fixed memory leaks and removed repeated code
Diffstat (limited to 'testing/experiment')
-rw-r--r-- | testing/experiment/group_chats_test1.c | 21 |
1 files changed, 7 insertions, 14 deletions
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 @@ | |||
1 | #include "../../toxcore/group_chats.h" | 1 | #include "../../toxcore/group_chats.h" |
2 | #include "../misc_tools.c" // hex_string_to_bin | ||
3 | |||
2 | #define NUM_CHATS 8 | 4 | #define NUM_CHATS 8 |
3 | 5 | ||
4 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | 6 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) |
@@ -54,19 +56,6 @@ void print_group(Group_Chat *chat) | |||
54 | } | 56 | } |
55 | } | 57 | } |
56 | 58 | ||
57 | unsigned char *hex_string_to_bin(char hex_string[]) | ||
58 | { | ||
59 | size_t len = strlen(hex_string); | ||
60 | unsigned char *val = malloc(len); | ||
61 | char *pos = hex_string; | ||
62 | int i; | ||
63 | |||
64 | for (i = 0; i < len; ++i, pos += 2) | ||
65 | sscanf(pos, "%2hhx", &val[i]); | ||
66 | |||
67 | return val; | ||
68 | } | ||
69 | |||
70 | void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) | 59 | void print_message(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) |
71 | { | 60 | { |
72 | printf("%u: %s | %u\n", peer_number, message, length); | 61 | printf("%u: %s | %u\n", peer_number, message, length); |
@@ -95,8 +84,12 @@ int main(int argc, char *argv[]) | |||
95 | * bootstrap_ip_port.ip.c[2] = 0; | 84 | * bootstrap_ip_port.ip.c[2] = 0; |
96 | * bootstrap_ip_port.ip.c[3] = 1; */ | 85 | * bootstrap_ip_port.ip.c[3] = 1; */ |
97 | bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); | 86 | bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); |
87 | |||
88 | uint8_t *bootstrap_id = hex_string_to_bin(argv[3]); | ||
98 | 89 | ||
99 | chat_bootstrap(chat, bootstrap_ip_port, hex_string_to_bin(argv[3])); | 90 | chat_bootstrap(chat, bootstrap_ip_port, bootstrap_id); |
91 | |||
92 | free(bootstrap_id); | ||
100 | 93 | ||
101 | while (1) { | 94 | while (1) { |
102 | 95 | ||