Commit 021c229331444aae507186c7b4a54bb1692b5846
1 parent
ad527a64
Fix Pl_Flate memory leak on error (fixes #148)
Showing
1 changed file
with
15 additions
and
0 deletions
libqpdf/Pl_Flate.cc
| ... | ... | @@ -35,6 +35,20 @@ Pl_Flate::~Pl_Flate() |
| 35 | 35 | delete [] this->outbuf; |
| 36 | 36 | this->outbuf = 0; |
| 37 | 37 | } |
| 38 | + | |
| 39 | + if (this->initialized) | |
| 40 | + { | |
| 41 | + z_stream& zstream = *(static_cast<z_stream*>(this->zdata)); | |
| 42 | + if (action == a_deflate) | |
| 43 | + { | |
| 44 | + deflateEnd(&zstream); | |
| 45 | + } | |
| 46 | + else | |
| 47 | + { | |
| 48 | + inflateEnd(&zstream); | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 38 | 52 | delete static_cast<z_stream*>(this->zdata); |
| 39 | 53 | this->zdata = 0; |
| 40 | 54 | } |
| ... | ... | @@ -174,6 +188,7 @@ Pl_Flate::finish() |
| 174 | 188 | { |
| 175 | 189 | err = inflateEnd(&zstream); |
| 176 | 190 | } |
| 191 | + this->initialized = false; | |
| 177 | 192 | checkError("End", err); |
| 178 | 193 | } |
| 179 | 194 | ... | ... |