From: Eric Biggers Date: Wed, 25 Jun 2014 02:39:08 +0000 (-0500) Subject: Close error file opened by name X-Git-Tag: v1.7.1~80 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=ce4af1bc0291503cae1b053d53efbc4123c50be5;hp=e61f93d517a76c23a3bfc2fdbd32fa190fbbc286 Close error file opened by name --- diff --git a/src/util.c b/src/util.c index 86fcb059..3bb78efb 100644 --- a/src/util.c +++ b/src/util.c @@ -67,6 +67,7 @@ utf16le_strlen(const utf16lechar *s) #ifdef ENABLE_ERROR_MESSAGES bool wimlib_print_errors = false; FILE *wimlib_error_file = NULL; /* Set in wimlib_global_init() */ +static bool wimlib_owns_error_file = false; #endif #if defined(ENABLE_ERROR_MESSAGES) || defined(ENABLE_DEBUG) @@ -192,8 +193,11 @@ WIMLIBAPI int wimlib_set_error_file(FILE *fp) { #ifdef ENABLE_ERROR_MESSAGES + if (wimlib_owns_error_file) + fclose(wimlib_error_file); wimlib_error_file = fp; - wimlib_print_errors = true; + wimlib_print_errors = (fp != NULL); + wimlib_owns_error_file = false; return 0; #else return WIMLIB_ERR_UNSUPPORTED; @@ -209,9 +213,8 @@ wimlib_set_error_file_by_name(const char *path) fp = fopen(path, "a"); if (!fp) return WIMLIB_ERR_OPEN; - - wimlib_error_file = fp; - wimlib_print_errors = true; + wimlib_set_error_file(fp); + wimlib_owns_error_file = true; return 0; #else return WIMLIB_ERR_UNSUPPORTED; diff --git a/src/wim.c b/src/wim.c index 38d90718..fc15a21d 100644 --- a/src/wim.c +++ b/src/wim.c @@ -1071,5 +1071,7 @@ wimlib_global_cleanup(void) #endif cleanup_decompressor_params(); cleanup_compressor_params(); + + wimlib_set_error_file(NULL); lib_initialized = false; }