h2_session *session;
} h2_bucket_eoc;
-static apr_status_t bucket_cleanup(void *data)
-{
- h2_session **psession = data;
-
- if (*psession) {
- /*
- * If bucket_destroy is called after us, this prevents
- * bucket_destroy from trying to destroy the pool again.
- */
- *psession = NULL;
- }
- return APR_SUCCESS;
-}
-
static apr_status_t bucket_read(apr_bucket *b, const char **str,
apr_size_t *len, apr_read_type_e block)
{
APR_BUCKET_INIT(b);
b->free = apr_bucket_free;
b->list = list;
- b = h2_bucket_eoc_make(b, session);
- if (session) {
- h2_bucket_eoc *h = b->data;
- apr_pool_pre_cleanup_register(session->pool, &h->session, bucket_cleanup);
- }
- return b;
+ return h2_bucket_eoc_make(b, session);
}
static void bucket_destroy(void *data)
if (apr_bucket_shared_destroy(h)) {
h2_session *session = h->session;
apr_bucket_free(h);
- if (session) {
- h2_session_eoc_callback(session);
- /* all is gone now */
- }
+ h2_session_eoc_callback(session);
}
}
return APR_SUCCESS;
}
-static void h2_session_destroy(h2_session *session)
+static void h2_session_cleanup(h2_session *session)
{
ap_assert(session);
if (APLOGctrace1(session->c)) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
- "h2_session(%ld): destroy", session->id);
- }
- if (session->pool) {
- apr_pool_destroy(session->pool);
+ "h2_session(%ld): cleanup", session->id);
}
}
+static void h2_session_destroy(h2_session *session)
+{
+ apr_pool_t *p = session->pool;
+ session->pool = NULL;
+ apr_pool_destroy(p);
+}
+
static apr_status_t h2_session_shutdown_notice(h2_session *session)
{
apr_status_t status;
"goodbye, clients will be confused, should not happen",
session->id);
}
- /* keep us from destroying the pool, since that is already ongoing. */
+ h2_session_cleanup(session);
session->pool = NULL;
- h2_session_destroy(session);
return APR_SUCCESS;
}
}
apr_pool_tag(pool, "h2_session");
- session = apr_pcalloc(pool, sizeof(h2_session));
+ /* get h2_session a lifetime beyond its pool and everything
+ * connected to it. */
+ session = apr_pcalloc(c->pool, sizeof(h2_session));
if (session) {
int rv;
nghttp2_mem *mem;
h2_session_destroy(session);
return NULL;
}
-
+
n = h2_config_geti(session->config, H2_CONF_PUSH_DIARY_SIZE);
session->push_diary = h2_push_diary_create(session->pool, n);
void h2_session_eoc_callback(h2_session *session)
{
- ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
- "session(%ld): cleanup and destroy", session->id);
- apr_pool_cleanup_kill(session->pool, session, session_pool_cleanup);
- h2_session_destroy(session);
+ /* keep us from destroying the pool, if it's already done (cleanup). */
+ if (session->pool) {
+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
+ "session(%ld): cleanup and destroy", session->id);
+ apr_pool_cleanup_kill(session->pool, session, session_pool_cleanup);
+ h2_session_cleanup(session);
+ h2_session_destroy(session);
+ }
}
static apr_status_t h2_session_start(h2_session *session, int *rv)