Chromium Code Reviews| Index: third_party/zlib/google/zip_internal.cc |
| diff --git a/third_party/zlib/google/zip_internal.cc b/third_party/zlib/google/zip_internal.cc |
| index d62e0bbf21141b32194612d567e962f052463d2c..cd2c0eb1748f247bb38731e3c630062a8c70ff82 100644 |
| --- a/third_party/zlib/google/zip_internal.cc |
| +++ b/third_party/zlib/google/zip_internal.cc |
| @@ -90,17 +90,17 @@ void* FdOpenFileFunc(void* opaque, const char* filename, int mode) { |
| else if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
| mode_fopen = "wb"; |
| - if ((filename != NULL) && (mode_fopen != NULL)) |
| - file = fdopen(*static_cast<int*>(opaque), mode_fopen); |
| + if ((filename != NULL) && (mode_fopen != NULL)) { |
| + int fd = dup(*static_cast<int*>(opaque)); |
| + if (fd != -1) |
| + file = fdopen(fd, mode_fopen); |
| + } |
| return file; |
| } |
| -// We don't actually close the file stream since that would close |
| -// the underlying file descriptor, and we don't own it. However we do need to |
| -// flush buffers and free |opaque| since we malloc'ed it in FillFdOpenFileFunc. |
| int CloseFileFunc(void* opaque, void* stream) { |
| - fflush(static_cast<FILE*>(stream)); |
| + fclose(static_cast<FILE*>(stream)); |
| free(opaque); |
| return 0; |
| } |
| @@ -131,6 +131,11 @@ void* HandleOpenFileFunc(void* opaque, const char* filename, int mode) { |
| *(static_cast<WIN32FILE_IOWIN*>(ret)) = file_ret; |
| return ret; |
| } |
| + |
| +int HandleCloseFileFunc(void* opaque, void* stream) { |
| + free(stream); |
|
satorux1
2014/11/12 07:04:43
Good catch!
maybe add a comment: // malloc'ed in
jeremyspiegel
2014/11/12 08:52:51
Sounds good.
|
| + return 0; |
| +} |
| #endif |
| // A struct that contains data required for zlib functions to extract files from |
| @@ -282,6 +287,7 @@ unzFile OpenHandleForUnzipping(HANDLE zip_handle) { |
| zlib_filefunc_def zip_funcs; |
| fill_win32_filefunc(&zip_funcs); |
| zip_funcs.zopen_file = HandleOpenFileFunc; |
| + zip_funcs.zclose_file = HandleCloseFileFunc; |
| zip_funcs.opaque = zip_handle; |
| return unzOpen2("fd", &zip_funcs); |
| } |