diff --git a/src/or/relay.c b/src/or/relay.c
index 7947ca373a..e0b5d26fe3 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -2204,7 +2204,9 @@ cell_command_queue_pop(uint8_t *command, cell_queue_t *queue)
}
/** Append a newly allocated copy of cell to the end of the
- * exitward (or app-ward) queue of circ. */
+ * exitward (or app-ward) queue of circ. If
+ * use_stats is true, record statistics about the cell.
+ */
void
cell_queue_append_packed_copy(circuit_t *circ, cell_queue_t *queue,
int exitward, const cell_t *cell,
@@ -2244,7 +2246,7 @@ cell_queue_append_packed_copy(circuit_t *circ, cell_queue_t *queue,
}
/* Remember that we added a cell to the queue, and remember the cell
* command. */
- if (get_options()->TestingEnableCellStatsEvent) {
+ if (get_options()->TestingEnableCellStatsEvent && circ) {
testing_cell_stats_entry_t *ent =
tor_malloc_zero(sizeof(testing_cell_stats_entry_t));
ent->command = cell->command;