Skip to content

Commit ae7656e

Browse files
libvncclient: fix memory leak in CompressClipData
1 parent 5b068d1 commit ae7656e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/libvncclient/rfbclient.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,26 +1815,26 @@ static int
18151815
CompressClipData(Bytef *dest, uLongf *destLen, Bytef *source, uLong sourceLen)
18161816
{
18171817
int ret;
1818-
z_stream *zs = (z_stream*)malloc(sizeof(z_stream));
1819-
memset(zs, 0, sizeof(z_stream));
1818+
z_stream zs;
1819+
memset(&zs, 0, sizeof(z_stream));
18201820

1821-
zs->zfree = Z_NULL;
1822-
zs->zalloc = Z_NULL;
1823-
zs->opaque = Z_NULL;
1824-
ret = deflateInit(zs, Z_DEFAULT_COMPRESSION);
1821+
zs.zfree = Z_NULL;
1822+
zs.zalloc = Z_NULL;
1823+
zs.opaque = Z_NULL;
1824+
ret = deflateInit(&zs, Z_DEFAULT_COMPRESSION);
18251825
if (ret == Z_OK) {
1826-
zs->avail_in = sourceLen;
1827-
zs->next_in = source;
1828-
zs->avail_out = *destLen;
1829-
zs->next_out = dest;
1826+
zs.avail_in = sourceLen;
1827+
zs.next_in = source;
1828+
zs.avail_out = *destLen;
1829+
zs.next_out = dest;
18301830

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

1836-
*destLen = zs->total_out;
1837-
deflateEnd(zs);
1836+
*destLen = zs.total_out;
1837+
deflateEnd(&zs);
18381838
}
18391839
return ret;
18401840
}

0 commit comments

Comments
 (0)