From 021c229331444aae507186c7b4a54bb1692b5846 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 25 Aug 2017 22:26:53 -0400 Subject: Fix Pl_Flate memory leak on error (fixes #148) --- libqpdf/Pl_Flate.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libqpdf/Pl_Flate.cc') diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc index ce4c9ed1..212f7e1d 100644 --- a/libqpdf/Pl_Flate.cc +++ b/libqpdf/Pl_Flate.cc @@ -35,6 +35,20 @@ Pl_Flate::~Pl_Flate() delete [] this->outbuf; this->outbuf = 0; } + + if (this->initialized) + { + z_stream& zstream = *(static_cast(this->zdata)); + if (action == a_deflate) + { + deflateEnd(&zstream); + } + else + { + inflateEnd(&zstream); + } + } + delete static_cast(this->zdata); this->zdata = 0; } @@ -174,6 +188,7 @@ Pl_Flate::finish() { err = inflateEnd(&zstream); } + this->initialized = false; checkError("End", err); } -- cgit v1.2.3-54-g00ecf