diff --git a/src/memchunk.h b/src/memchunk.h index 7e1bd8e2..43e4bfa9 100644 --- a/src/memchunk.h +++ b/src/memchunk.h @@ -114,6 +114,9 @@ template struct Memchunks { Memchunks(Pool *pool) : pool(pool), head(nullptr), tail(nullptr), len(0) {} ~Memchunks() { + if (!pool) { + return; + } for (auto m = head; m;) { auto next = m->next; pool->recycle(m); diff --git a/src/shrpx-unittest.cc b/src/shrpx-unittest.cc index e4778060..1e4e2041 100644 --- a/src/shrpx-unittest.cc +++ b/src/shrpx-unittest.cc @@ -39,6 +39,7 @@ #include "util_test.h" #include "nghttp2_gzip_test.h" #include "ringbuf_test.h" +#include "shrpx_config.h" static int init_suite1(void) { return 0; } @@ -52,6 +53,8 @@ int main(int argc, char *argv[]) { SSL_load_error_strings(); SSL_library_init(); + shrpx::create_config(); + // initialize the CUnit test registry if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index ceba2c94..ea84efff 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -104,13 +104,14 @@ void downstream_wtimeoutcb(struct ev_loop *loop, ev_timer *w, int revents) { } } // namespace +// upstream could be nullptr for unittests Downstream::Downstream(Upstream *upstream, int32_t stream_id, int32_t priority) - : request_buf_(upstream->get_mcpool()), - response_buf_(upstream->get_mcpool()), request_bodylen_(0), - response_bodylen_(0), response_sent_bodylen_(0), upstream_(upstream), - request_headers_sum_(0), response_headers_sum_(0), request_datalen_(0), - response_datalen_(0), stream_id_(stream_id), priority_(priority), - downstream_stream_id_(-1), + : request_buf_(upstream ? upstream->get_mcpool() : nullptr), + response_buf_(upstream ? upstream->get_mcpool() : nullptr), + request_bodylen_(0), response_bodylen_(0), response_sent_bodylen_(0), + upstream_(upstream), request_headers_sum_(0), response_headers_sum_(0), + request_datalen_(0), response_datalen_(0), stream_id_(stream_id), + priority_(priority), downstream_stream_id_(-1), response_rst_stream_error_code_(NGHTTP2_NO_ERROR), request_state_(INITIAL), request_major_(1), request_minor_(1), response_state_(INITIAL), response_http_status_(0), response_major_(1), @@ -141,12 +142,16 @@ Downstream::~Downstream() { if (LOG_ENABLED(INFO)) { DLOG(INFO, this) << "Deleting"; } - auto loop = upstream_->get_client_handler()->get_loop(); - ev_timer_stop(loop, &upstream_rtimer_); - ev_timer_stop(loop, &upstream_wtimer_); - ev_timer_stop(loop, &downstream_rtimer_); - ev_timer_stop(loop, &downstream_wtimer_); + // check nullptr for unittest + if (upstream_) { + auto loop = upstream_->get_client_handler()->get_loop(); + + ev_timer_stop(loop, &upstream_rtimer_); + ev_timer_stop(loop, &upstream_wtimer_); + ev_timer_stop(loop, &downstream_rtimer_); + ev_timer_stop(loop, &downstream_wtimer_); + } if (LOG_ENABLED(INFO)) { DLOG(INFO, this) << "Deleted";