diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-03-21 10:20:16 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-03-21 10:20:16 -0400 |
commit | cb3f9bc2d48e8c3f4847643c03e082d394d33168 (patch) | |
tree | 738d21dd0265596baf2f8fd5482a5a9508212e15 /src/or/connection_or.c | |
parent | a42938c07670162863decc952b4d73681d9302d6 (diff) | |
parent | 72ebf4160412f64fb6ae0cd97dd89d01d89c075a (diff) | |
download | tor-cb3f9bc2d48e8c3f4847643c03e082d394d33168.tar.gz tor-cb3f9bc2d48e8c3f4847643c03e082d394d33168.zip |
Merge branch 'bug18570_027'
Diffstat (limited to 'src/or/connection_or.c')
-rw-r--r-- | src/or/connection_or.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/or/connection_or.c b/src/or/connection_or.c index f39d5b2255..ea49bdba77 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -488,6 +488,28 @@ var_cell_new(uint16_t payload_len) return cell; } +/** + * Copy a var_cell_t + */ + +var_cell_t * +var_cell_copy(const var_cell_t *src) +{ + var_cell_t *copy = NULL; + size_t size = 0; + + if (src != NULL) { + size = STRUCT_OFFSET(var_cell_t, payload) + src->payload_len; + copy = tor_malloc_zero(size); + copy->payload_len = src->payload_len; + copy->command = src->command; + copy->circ_id = src->circ_id; + memcpy(copy->payload, src->payload, copy->payload_len); + } + + return copy; +} + /** Release all space held by <b>cell</b>. */ void var_cell_free(var_cell_t *cell) @@ -2026,6 +2048,19 @@ connection_or_process_cells_from_inbuf(or_connection_t *conn) { var_cell_t *var_cell; + /* + * Note on memory management for incoming cells: below the channel layer, + * we shouldn't need to consider its internal queueing/copying logic. It + * is safe to pass cells to it on the stack or on the heap, but in the + * latter case we must be sure we free them later. + * + * The incoming cell queue code in channel.c will (in the common case) + * decide it can pass them to the upper layer immediately, in which case + * those functions may run directly on the cell pointers we pass here, or + * it may decide to queue them, in which case it will allocate its own + * buffer and copy the cell. + */ + while (1) { log_debug(LD_OR, TOR_SOCKET_T_FORMAT": starting, inbuf_datalen %d " |