Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoke deflateEnd/inflateEnd to release memory #360

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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