Skip to content

Commit c28f67e

Browse files
halx99minggo
authored andcommitted
1 parent ece05ff commit c28f67e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

unzip/ioapi_mem.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ voidpf ZCALLBACK fopen_mem_func(voidpf opaque, ZIP_UNUSED const char *filename,
5656

5757
mem->cur_offset = 0;
5858

59-
return mem;
59+
/* pitfall: The builtin memfs management's behavior is not same with official minizip 1.2.0 */
60+
ourmemory_t* memfs = (ourmemory_t*)malloc(sizeof(ourmemory_t));
61+
if (memfs != nullptr) {
62+
memcpy(memfs, mem, sizeof(ourmemory_t));
63+
64+
return memfs;
65+
}
66+
return nullptr;
6067
}
6168

6269
voidpf ZCALLBACK fopendisk_mem_func(ZIP_UNUSED voidpf opaque, ZIP_UNUSED voidpf stream, ZIP_UNUSED uint32_t number_disk, ZIP_UNUSED int mode)
@@ -144,6 +151,10 @@ long ZCALLBACK fseek_mem_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint32_t
144151
int ZCALLBACK fclose_mem_func(ZIP_UNUSED voidpf opaque, ZIP_UNUSED voidpf stream)
145152
{
146153
/* Even with grow = 1, caller must always free() memory */
154+
155+
/* pitfall: The builtin memfs management's behavior is not same with official minizip 1.2.0 */
156+
ourmemory_t* mem = (ourmemory_t*)stream;
157+
free(mem);
147158
return 0;
148159
}
149160

0 commit comments

Comments
 (0)