Skip to content

Commit

Permalink
libvncclient: fix memory leak in CompressClipData
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpoelen authored Feb 6, 2025
1 parent 5b068d1 commit ae7656e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/libvncclient/rfbclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1815,26 +1815,26 @@ static int
CompressClipData(Bytef *dest, uLongf *destLen, Bytef *source, uLong sourceLen)
{
int ret;
z_stream *zs = (z_stream*)malloc(sizeof(z_stream));
memset(zs, 0, sizeof(z_stream));
z_stream zs;
memset(&zs, 0, sizeof(z_stream));

zs->zfree = Z_NULL;
zs->zalloc = Z_NULL;
zs->opaque = Z_NULL;
ret = deflateInit(zs, Z_DEFAULT_COMPRESSION);
zs.zfree = Z_NULL;
zs.zalloc = Z_NULL;
zs.opaque = Z_NULL;
ret = deflateInit(&zs, Z_DEFAULT_COMPRESSION);
if (ret == Z_OK) {
zs->avail_in = sourceLen;
zs->next_in = source;
zs->avail_out = *destLen;
zs->next_out = dest;
zs.avail_in = sourceLen;
zs.next_in = source;
zs.avail_out = *destLen;
zs.next_out = dest;

do {
// Using Z_SYNC_FLUSH instead of Z_FINISH is the key here.
ret = deflate(zs, Z_SYNC_FLUSH);
} while (ret >= 0 && zs->avail_in > 0);
ret = deflate(&zs, Z_SYNC_FLUSH);
} while (ret >= 0 && zs.avail_in > 0);

*destLen = zs->total_out;
deflateEnd(zs);
*destLen = zs.total_out;
deflateEnd(&zs);
}
return ret;
}
Expand Down

0 comments on commit ae7656e

Please sign in to comment.