handle_control_getconf(control_connection_t *conn, uint32_t body_len,
const char *body)
{
- smartlist_t *questions = NULL;
- smartlist_t *answers = NULL;
- smartlist_t *unrecognized = NULL;
+ smartlist_t *questions = smartlist_create();
+ smartlist_t *answers = smartlist_create();
+ smartlist_t *unrecognized = smartlist_create();
char *msg = NULL;
size_t msg_len;
or_options_t *options = get_options();
int i, len;
- questions = smartlist_create();
(void) body_len; /* body is nul-terminated; so we can ignore len. */
smartlist_split_string(questions, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- answers = smartlist_create();
- unrecognized = smartlist_create();
- SMARTLIST_FOREACH(questions, char *, q,
+ SMARTLIST_FOREACH(questions, const char *, q,
{
if (!option_is_recognized(q)) {
- smartlist_add(unrecognized, q);
+ smartlist_add(unrecognized, (char*) q);
} else {
config_line_t *answer = option_get_assignment(options,q);
if (!answer) {
connection_write_str_to_buf("250 OK\r\n", conn);
}
- if (answers) {
- SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
- smartlist_free(answers);
- }
- if (questions) {
- SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
- smartlist_free(questions);
- }
+ SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
+ smartlist_free(answers);
+ SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
+ smartlist_free(questions);
smartlist_free(unrecognized);
+
tor_free(msg);
return 0;
handle_control_getinfo(control_connection_t *conn, uint32_t len,
const char *body)
{
- smartlist_t *questions = NULL;
- smartlist_t *answers = NULL;
- smartlist_t *unrecognized = NULL;
+ smartlist_t *questions = smartlist_create();
+ smartlist_t *answers = smartlist_create();
+ smartlist_t *unrecognized = smartlist_create();
char *msg = NULL, *ans = NULL;
int i;
(void) len; /* body is nul-terminated, so it's safe to ignore the length. */
- questions = smartlist_create();
smartlist_split_string(questions, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- answers = smartlist_create();
- unrecognized = smartlist_create();
SMARTLIST_FOREACH(questions, const char *, q,
{
if (handle_getinfo_helper(conn, q, &ans) < 0) {
connection_write_str_to_buf("250 OK\r\n", conn);
done:
- if (answers) {
- SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
- smartlist_free(answers);
- }
- if (questions) {
- SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
- smartlist_free(questions);
- }
+ SMARTLIST_FOREACH(answers, char *, cp, tor_free(cp));
+ smartlist_free(answers);
+ SMARTLIST_FOREACH(questions, char *, cp, tor_free(cp));
+ smartlist_free(questions);
smartlist_free(unrecognized);
tor_free(msg);
static void
test_util_pqueue(void)
{
- smartlist_t *sl = NULL;
+ smartlist_t *sl = smartlist_create();
int (*cmp)(const void *, const void*);
#define OK() smartlist_pqueue_assert_ok(sl, cmp)
cmp = _compare_strings_for_pqueue;
- sl = smartlist_create();
smartlist_pqueue_add(sl, cmp, (char*)"cows");
smartlist_pqueue_add(sl, cmp, (char*)"zebras");
smartlist_pqueue_add(sl, cmp, (char*)"fish");
#undef OK
done:
- if (sl)
- smartlist_free(sl);
+
+ smartlist_free(sl);
}
/** Run unit tests for compression functions */
char address2[] = "aaaaaaaaaaaaaaaa.onion";
char address3[] = "fooaddress.exit";
char address4[] = "www.torproject.org";
- rend_service_descriptor_t *d1 = NULL, *d2 = NULL;
+ rend_service_descriptor_t *d1 =
+ tor_malloc_zero(sizeof(rend_service_descriptor_t));
+ rend_service_descriptor_t *d2 = NULL;
char *encoded = NULL;
size_t len;
- crypto_pk_env_t *pk1 = NULL, *pk2 = NULL;
time_t now;
int i;
- pk1 = pk_generate(0);
- pk2 = pk_generate(1);
+ crypto_pk_env_t *pk1 = pk_generate(0), *pk2 = pk_generate(1);
/* Test unversioned (v0) descriptor */
- d1 = tor_malloc_zero(sizeof(rend_service_descriptor_t));
d1->pk = crypto_pk_dup_key(pk1);
now = time(NULL);
d1->timestamp = now;
test_assert(EXIT_HOSTNAME == parse_extended_hostname(address3));
test_assert(NORMAL_HOSTNAME == parse_extended_hostname(address4));
+ crypto_free_pk_env(pk1);
+ crypto_free_pk_env(pk2);
+ pk1 = pk2 = NULL;
+ rend_service_descriptor_free(d1);
+ rend_service_descriptor_free(d2);
+ d1 = d2 = NULL;
+
done:
if (pk1)
crypto_free_pk_env(pk1);
test_eq(gen_info->port, par_info->port);
}
+ rend_service_descriptor_free(parsed);
+ rend_service_descriptor_free(generated);
+ parsed = generated = NULL;
+
done:
if (descs) {
for (i = 0; i < smartlist_len(descs); i++)