]> wimlib.net Git - wimlib/blobdiff - src/wim.c
Make different threads use different FILE*'s
[wimlib] / src / wim.c
index d065a590424c6c07d6e9d8ae7e87515f4d640b9e..bb76f855e9c6771bcadd9b972942627f3da74950 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -25,6 +25,7 @@
  */
 
 #include "config.h"
+#include <limits.h>
 #include <stdlib.h>
 #include <stdarg.h>
 
@@ -57,7 +58,14 @@ static int print_files(WIMStruct *w)
 
 WIMStruct *new_wim_struct()
 {
-       return CALLOC(1, sizeof(WIMStruct));
+       WIMStruct *w = CALLOC(1, sizeof(WIMStruct));
+       if (pthread_mutex_init(&w->fp_tab_mutex, NULL) != 0) {
+               ERROR_WITH_ERRNO("Failed to initialize mutex");
+               FREE(w);
+               w = NULL;
+       }
+       return w;
+
 }
 
 /*
@@ -407,7 +415,7 @@ static int begin_read(WIMStruct *w, const char *in_wim_path, int open_flags)
 
        DEBUG("Reading the WIM file `%s'", in_wim_path);
 
-       w->filename = STRDUP(in_wim_path);
+       w->filename = realpath(in_wim_path, NULL);
        if (!w->filename) {
                ERROR("Failed to allocate memory for WIM filename");
                return WIMLIB_ERR_NOMEM;
@@ -569,6 +577,14 @@ WIMLIBAPI void wimlib_free(WIMStruct *w)
        if (w->out_fp)
                fclose(w->out_fp);
 
+       if (w->fp_tab) {
+               for (size_t i = 0; i < w->num_allocated_fps; i++)
+                       if (w->fp_tab[i])
+                               fclose(w->fp_tab[i]);
+               FREE(w->fp_tab);
+       }
+       pthread_mutex_destroy(&w->fp_tab_mutex);
+
        free_lookup_table(w->lookup_table);
 
        FREE(w->filename);