channel_idmap_eq, 0.5, tor_reallocarray_, tor_free_);
static cell_queue_entry_t * cell_queue_entry_dup(cell_queue_entry_t *q);
-static void cell_queue_entry_free(cell_queue_entry_t *q, int handed_off);
#if 0
static int cell_queue_entry_is_padding(cell_queue_entry_t *q);
#endif
* them) or not (we should free).
*/
-static void
+STATIC void
cell_queue_entry_free(cell_queue_entry_t *q, int handed_off)
{
if (!q) return;
/* Cell queue functions for benefit of test suite */
STATIC int chan_cell_queue_len(const chan_cell_queue_t *queue);
+
+STATIC void cell_queue_entry_free(cell_queue_entry_t *q, int handed_off);
#endif
/* Channel operations for subclasses and internal use only */
#define parse_server_method_error(l) parse_method_error(l, 1)
#define parse_client_method_error(l) parse_method_error(l, 0)
-static INLINE void free_execve_args(char **arg);
-
/** Managed proxy protocol strings */
#define PROTO_ENV_ERROR "ENV-ERROR"
#define PROTO_NEG_SUCCESS "VERSION"
/** Frees the array of pointers in <b>arg</b> used as arguments to
execve(2). */
-static INLINE void
+STATIC void
free_execve_args(char **arg)
{
char **tmp = arg;
STATIC char* get_pt_proxy_uri(void);
+STATIC void free_execve_args(char **arg);
+
#endif
#endif
void make_fake_cell(cell_t *c);
void make_fake_var_cell(var_cell_t *c);
channel_t * new_fake_channel(void);
+void free_fake_channel(channel_t *c);
/* Also exposes some a mock used by both test_channel.c and test_relay.c */
void scheduler_channel_has_waiting_cells_mock(channel_t *ch);
return chan;
}
+void
+free_fake_channel(channel_t *chan)
+{
+ cell_queue_entry_t *cell, *cell_tmp;
+
+ if (! chan)
+ return;
+
+ if (chan->cmux)
+ circuitmux_free(chan->cmux);
+
+ TOR_SIMPLEQ_FOREACH_SAFE(cell, &chan->incoming_queue, next, cell_tmp) {
+ cell_queue_entry_free(cell, 0);
+ }
+ TOR_SIMPLEQ_FOREACH_SAFE(cell, &chan->outgoing_queue, next, cell_tmp) {
+ cell_queue_entry_free(cell, 0);
+ }
+
+ tor_free(chan);
+}
+
/**
* Counter query for scheduler_channel_has_waiting_cells_mock()
*/
done:
tor_free(cell);
- tor_free(ch);
+ free_fake_channel(ch);
UNMOCK(scheduler_channel_doesnt_want_writes);
UNMOCK(scheduler_release_channel);
test_cmux_cells = 0;
done:
+ if (ch)
+ circuitmux_free(ch->cmux);
tor_free(ch);
UNMOCK(channel_flush_from_first_active_circuit);
ch = NULL;
done:
- tor_free(ch);
+ free_fake_channel(ch);
tor_free(cell);
tor_free(var_cell);
tt_int_op(test_releases_count, ==, init_releases_count + 4);
done:
- tor_free(ch1);
- tor_free(ch2);
+ free_fake_channel(ch1);
+ free_fake_channel(ch2);
UNMOCK(scheduler_channel_doesnt_want_writes);
UNMOCK(scheduler_release_channel);
cell = tor_malloc_zero(sizeof(cell_t));
make_fake_cell(cell);
channel_write_cell(ch2, cell);
+ cell = NULL;
/* Check the estimates */
channel_update_xmit_queue_size(ch1);
UNMOCK(scheduler_release_channel);
done:
- tor_free(ch1);
- tor_free(ch2);
+ free_fake_channel(ch1);
+ free_fake_channel(ch2);
return;
}
init_cell_pool();
#endif /* ENABLE_MEMPOOLS */
- packed_cell = packed_cell_new();
- tt_assert(packed_cell);
-
ch = new_fake_channel();
tt_assert(ch);
tt_int_op(chan_cell_queue_len(&(ch->outgoing_queue)), ==, 0);
done:
- tor_free(ch);
+ free_fake_channel(ch);
#ifdef ENABLE_MEMPOOLS
free_cell_pool();
#endif /* ENABLE_MEMPOOLS */
UNMOCK(scheduler_release_channel);
done:
- tor_free(ch);
+ free_fake_channel(ch);
return;
}
#endif /* ENABLE_MEMPOOLS */
done:
- tor_free(ch);
+ free_fake_channel(ch);
tor_free(var_cell);
tor_free(cell);
packed_cell_free(packed_cell);
*/
ch->close = tlschan_fake_close_method;
channel_mark_for_close(ch);
- tor_free(ch);
+ free_fake_channel(ch);
UNMOCK(scheduler_release_channel);
}
*/
ch->close = tlschan_fake_close_method;
channel_mark_for_close(ch);
- tor_free(ch);
+ free_fake_channel(ch);
UNMOCK(scheduler_release_channel);
}
*/
ch->close = tlschan_fake_close_method;
channel_mark_for_close(ch);
- tor_free(ch);
+ free_fake_channel(ch);
UNMOCK(scheduler_release_channel);
}
tt_assert(tlschan != NULL);
/* Just free the fake orconn */
+ tor_free(tlschan->conn->base_.address);
tor_free(tlschan->conn);
channel_closed(chan);
#include "orconfig.h"
#define CONFIG_PRIVATE
+#define PT_PRIVATE
#include "or.h"
#include "addressmap.h"
#include "config.h"
/* XXXX check that args are as expected. */
++pt_kickstart_proxy_mock_call_count;
+
+ free_execve_args(proxy_argv);
}
static int
#include "example_extrainfo.inc"
+static void
+routerinfo_free_wrapper_(void *arg)
+{
+ routerinfo_free(arg);
+}
+
static void
test_dir_extrainfo_parsing(void *arg)
{
#undef CHECK_FAIL
done:
+ extrainfo_free(ei);
routerinfo_free(ri);
- /* XXXX elements should get freed too */
- digestmap_free((digestmap_t*)map, NULL);
+ digestmap_free((digestmap_t*)map, routerinfo_free_wrapper_);
}
static void
SMARTLIST_FOREACH(chunks, char *, cp, tor_free(cp));
smartlist_free(chunks);
routerinfo_free(ri);
- /* XXXX this leaks: */
if (map) {
- digestmap_free((digestmap_t*)map, NULL);
+ digestmap_free((digestmap_t*)map, routerinfo_free_wrapper_);
router_get_routerlist()->identity_map =
(struct digest_ri_map_t*)digestmap_new();
}
/* Shut down channels */
channel_free_all();
- nchan = pchan = NULL;
done:
tor_free(cell);
+ cell_queue_clear(&orcirc->base_.n_chan_cells);
+ cell_queue_clear(&orcirc->p_chan_cells);
tor_free(orcirc);
- if (nchan && nchan->cmux) circuitmux_free(nchan->cmux);
- tor_free(nchan);
- if (pchan && pchan->cmux) circuitmux_free(pchan->cmux);
- tor_free(pchan);
+ free_fake_channel(nchan);
+ free_fake_channel(pchan);
#ifdef ENABLE_MEMPOOLS
free_cell_pool();
#endif /* ENABLE_MEMPOOLS */