From 0a228d0740607669ba098cb3f71502d358e5dbd4 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 20 Sep 2015 16:59:26 -0700 Subject: [PATCH] libobs/util: Use gzopen* instead of gzdopen Using gzdopen will not work properly if the C standard library used to get the descriptor is not the same library as the one that was compiled with zlib. When this is the case, it causes zlib to fail to write a file, and would report a C standard library error. Use gzopen and gzopen_w instead to ensure that the file is opened and closed by zlib itself, ensuring that zlib and the libobs do not have to share the C standard library between each other. --- libobs/util/profiler.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libobs/util/profiler.c b/libobs/util/profiler.c index 4521a7914..2838971dd 100644 --- a/libobs/util/profiler.c +++ b/libobs/util/profiler.c @@ -1043,11 +1043,19 @@ static void dump_csv_gzwrite(void *data, struct dstr *buffer) bool profiler_snapshot_dump_csv_gz(const profiler_snapshot_t *snap, const char *filename) { - FILE *f = os_fopen(filename, "wb"); - if (!f) + gzFile gz; +#ifdef _WIN32 + wchar_t *filename_w = NULL; + + os_utf8_to_wcs_ptr(filename, 0, &filename_w); + if (!filename_w) return false; - gzFile gz = gzdopen(fileno(f), "wb"); + gz = gzopen_w(filename_w, "wb"); + bfree(filename_w); +#else + gz = gzopen(filename, "wb"); +#endif if (!gz) return false;