From c8dacbb6456682351c90b8424966ab466a4fb6e9 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Wed, 7 Feb 2018 23:37:50 +0000 Subject: [PATCH] VFS: Fix crash when built with minizip --- src/util/vfs/vfs-zip.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util/vfs/vfs-zip.c b/src/util/vfs/vfs-zip.c index 13220a30320..c3849d8e7f8 100644 --- a/src/util/vfs/vfs-zip.c +++ b/src/util/vfs/vfs-zip.c @@ -61,6 +61,7 @@ struct VFileZip { struct VFile d; unzFile z; void* buffer; + size_t bufferSize; size_t fileSize; }; #endif @@ -451,7 +452,9 @@ static enum VFSType _vdezType(struct VDirEntry* vde) { bool _vfzClose(struct VFile* vf) { struct VFileZip* vfz = (struct VFileZip*) vf; unzCloseCurrentFile(vfz->z); - free(vfz->buffer); + if (vfz->buffer) { + mappedMemoryFree(vfz->buffer, vfz->bufferSize); + } free(vfz); return true; } @@ -536,6 +539,8 @@ void* _vfzMap(struct VFile* vf, size_t size, int flags) { unzOpenCurrentFile(vfz->z); vf->seek(vf, pos, SEEK_SET); + vfz->bufferSize = size; + return vfz->buffer; } @@ -619,6 +624,7 @@ struct VFile* _vdzOpenFile(struct VDir* vd, const char* path, int mode) { struct VFileZip* vfz = malloc(sizeof(struct VFileZip)); vfz->z = vdz->z; vfz->buffer = 0; + vfz->bufferSize = 0; vfz->fileSize = info.uncompressed_size; vfz->d.close = _vfzClose;