From 4690985fcac9bb336162412c1e5b0c5e293bf0b1 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 15 Nov 2012 14:57:56 +0100 Subject: [PATCH] BUG: compression: do not always increment the round counter on allocation failure Zlib (at least 1.2 and 1.3) aborts when it fails to allocate the state, so we must not count a round on this event. If the state succeeds, then it allocates all the 4 remaining counters at once. --- src/compression.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compression.c b/src/compression.c index 300a0bd40..abceddfc9 100644 --- a/src/compression.c +++ b/src/compression.c @@ -393,7 +393,13 @@ static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size) end: - round = (round + 1) % 5; /* there are 5 zalloc call in deflateInit2 */ + /* deflateInit2() first allocates and checks the deflate_state, then if + * it succeeds, it allocates all other 4 areas at ones and checks them + * at the end. So we want to correctly count the rounds depending on when + * zlib is supposed to abort. + */ + if (buf || round) + round = (round + 1) % 5; return buf; }