Merged r1416 from trunk.

git-svn-id: https://svn.apache.org/repos/asf/serf/branches/0.7.x@1698960 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/buckets/deflate_buckets.c b/buckets/deflate_buckets.c
index 8200641..05c6e03 100644
--- a/buckets/deflate_buckets.c
+++ b/buckets/deflate_buckets.c
@@ -121,6 +121,10 @@
 {
     deflate_context_t *ctx = bucket->data;
 
+    if (ctx->state > STATE_INIT &&
+        ctx->state <= STATE_FINISH)
+        inflateEnd(&ctx->zstream);
+
     /* We may have appended inflate_stream into the stream bucket.
      * If so, avoid free'ing it twice.
      */