BUG/MINOR: compression: deinit zlib only when required
The zlib stream was deinitialized even when the init failed.
diff --git a/include/types/session.h b/include/types/session.h
index f0a5be6..284b7e8 100644
--- a/include/types/session.h
+++ b/include/types/session.h
@@ -89,6 +89,8 @@
#define SN_BE_TRACK_SC1 0x00100000 /* backend tracks stick-counter 1 */
#define SN_BE_TRACK_SC2 0x00200000 /* backend tracks stick-counter 2 */
+#define SN_COMP_READY 0x00400000 /* the compression is initialized */
+
/* WARNING: if new fields are added, they must be initialized in event_accept()
* and freed in session_free() !
diff --git a/src/proto_http.c b/src/proto_http.c
index 4fc37ed..1836405 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -2103,6 +2103,8 @@
if (s->comp_algo->init(&s->comp_ctx, global.tune.comp_maxlevel) < 0)
goto fail;
+ s->flags |= SN_COMP_READY;
+
s->comp_ctx.cur_lvl = global.tune.comp_maxlevel;
/* remove Content-Length header */
@@ -2131,9 +2133,10 @@
return 1;
fail:
- if (s->comp_algo) {
+ if (s->flags & SN_COMP_READY) {
s->comp_algo->end(&s->comp_ctx);
s->comp_algo = NULL;
+ s->flags &= ~SN_COMP_READY;
}
return 0;
}
diff --git a/src/session.c b/src/session.c
index 0b0a4ec..f42f942 100644
--- a/src/session.c
+++ b/src/session.c
@@ -565,9 +565,10 @@
sess_change_server(s, NULL);
}
- if (s->comp_algo) {
+ if (s->flags & SN_COMP_READY) {
s->comp_algo->end(&s->comp_ctx);
s->comp_algo = NULL;
+ s->flags &= ~SN_COMP_READY;
}
if (s->req->pipe)