MINOR: h2: provide and use h2s_detach() and h2s_free()
These ones save us from open-coding the cleanup functions on each and
every error path. The code was updated to use them with no functional
change.
diff --git a/src/mux_h2.c b/src/mux_h2.c
index b73b67b..b8e621a 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -642,6 +642,19 @@
h2s->st = H2_SS_CLOSED;
}
+/* detaches an H2 stream from its H2C. */
+static void h2s_detach(struct h2s *h2s)
+{
+ h2s_close(h2s);
+ eb32_delete(&h2s->by_id);
+}
+
+/* releases an H2 stream back to the pool, and detaches it from the h2c. */
+static void h2s_free(struct h2s *h2s)
+{
+ pool_free(pool_head_h2s, h2s);
+}
+
/* creates a new stream <id> on the h2c connection and returns it, or NULL in
* case of memory allocation error.
*/
@@ -686,9 +699,8 @@
out_free_cs:
cs_free(cs);
out_close:
- h2c->nb_streams--;
- eb32_delete(&h2s->by_id);
- pool_free(pool_head_h2s, h2s);
+ h2s_detach(h2s);
+ h2s_free(h2s);
h2s = NULL;
out:
return h2s;
@@ -1048,9 +1060,8 @@
if (!h2s->cs) {
/* this stream was already orphaned */
- h2s_close(h2s);
- eb32_delete(&h2s->by_id);
- pool_free(pool_head_h2s, h2s);
+ h2s_detach(h2s);
+ h2s_free(h2s);
continue;
}
@@ -2081,9 +2092,8 @@
h2s->cs->flags &= ~CS_FL_DATA_WR_ENA;
else {
/* just sent the last frame for this orphaned stream */
- h2s_close(h2s);
- eb32_delete(&h2s->by_id);
- pool_free(pool_head_h2s, h2s);
+ h2s_detach(h2s);
+ h2s_free(h2s);
}
}
}
@@ -2124,9 +2134,8 @@
h2s->cs->flags &= ~CS_FL_DATA_WR_ENA;
else {
/* just sent the last frame for this orphaned stream */
- h2s_close(h2s);
- eb32_delete(&h2s->by_id);
- pool_free(pool_head_h2s, h2s);
+ h2s_detach(h2s);
+ h2s_free(h2s);
}
}
}
@@ -2494,8 +2503,7 @@
if (h2s->by_id.node.leaf_p) {
/* h2s still attached to the h2c */
- h2s_close(h2s);
- eb32_delete(&h2s->by_id);
+ h2s_detach(h2s);
/* We don't want to close right now unless we're removing the
* last stream, and either the connection is in error, or it
@@ -2520,7 +2528,7 @@
h2c->task->expire = TICK_ETERNITY;
}
}
- pool_free(pool_head_h2s, h2s);
+ h2s_free(h2s);
}
static void h2_shutr(struct conn_stream *cs, enum cs_shr_mode mode)