Skip to content

Commit

Permalink
invoke deflateEnd/inflateEnd to release memory (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
kedixa authored Feb 5, 2024
1 parent cce3754 commit 27e34fb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/compress/rpc_compress_gzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ static int CommonCompress(const char *msg, size_t msglen,
while (c_stream.avail_in != 0 && c_stream.total_in < buflen)
{
if (deflate(&c_stream, Z_NO_FLUSH) != Z_OK)
{
deflateEnd(&c_stream);
return -1;
}
}

if (c_stream.avail_in != 0)
Expand All @@ -139,7 +142,10 @@ static int CommonCompress(const char *msg, size_t msglen,
break;

if(err != Z_OK)
{
deflateEnd(&c_stream);
return -1;
}
}

if (deflateEnd(&c_stream) != Z_OK)
Expand Down Expand Up @@ -203,12 +209,18 @@ static int CommonDecompress(const char *buf, size_t buflen, char *msg, size_t ms
if (err != Z_OK)
{
if (err != Z_DATA_ERROR)
{
inflateEnd(&d_stream);
return -1;
}

d_stream.next_in = (Bytef*) dummy_head;
d_stream.avail_in = sizeof (dummy_head);
if (inflate(&d_stream, Z_NO_FLUSH) != Z_OK)
{
inflateEnd(&d_stream);
return -1;
}
}
}

Expand Down Expand Up @@ -247,23 +259,32 @@ static int CommonCompressIOVec(RPCBuffer *src, RPCBuffer *dst, int option_format
if (c_stream.avail_in == 0)
{
if ((c_stream.avail_in = (uInt)src->fetch(&in)) == 0)
{
deflateEnd(&c_stream);
return -1;
}

c_stream.next_in = static_cast<Bytef *>(const_cast<void *>(in));
}

if (c_stream.avail_out == 0)
{
if (dst->acquire(&out, &out_len) == false)
{
deflateEnd(&c_stream);
return -1;
}

total_alloc += out_len;
c_stream.next_out = static_cast<Bytef *>(out);
c_stream.avail_out = (uInt)out_len;
}

if (deflate(&c_stream, Z_NO_FLUSH) != Z_OK)
{
deflateEnd(&c_stream);
return -1;
}
}

// if (c_stream.avail_in != 0)
Expand All @@ -286,7 +307,10 @@ static int CommonCompressIOVec(RPCBuffer *src, RPCBuffer *dst, int option_format
break;

if(err != Z_OK)
{
deflateEnd(&c_stream);
return -1;
}
}

if (deflateEnd(&c_stream) != Z_OK)
Expand Down Expand Up @@ -346,15 +370,21 @@ static int CommonDecompressIOVec(RPCBuffer *src, RPCBuffer *dst)
if (d_stream.avail_in == 0)
{
if ((d_stream.avail_in = (uInt)src->fetch(&in)) == 0)
{
inflateEnd(&d_stream);
return -1;
}

d_stream.next_in = static_cast<Bytef *>(const_cast<void *>(in));
}

if (d_stream.avail_out == 0)
{
if (dst->acquire(&out, &out_len) == false)
{
inflateEnd(&d_stream);
return -1;
}

total_alloc += out_len;
d_stream.next_out = static_cast<Bytef *>(out);
Expand All @@ -368,12 +398,18 @@ static int CommonDecompressIOVec(RPCBuffer *src, RPCBuffer *dst)
if (err != Z_OK)
{
if (err != Z_DATA_ERROR)
{
inflateEnd(&d_stream);
return -1;
}

d_stream.next_in = (Bytef*) dummy_head;
d_stream.avail_in = sizeof (dummy_head);
if (inflate(&d_stream, Z_NO_FLUSH) != Z_OK)
{
inflateEnd(&d_stream);
return -1;
}
}
}

Expand Down

0 comments on commit 27e34fb

Please sign in to comment.