]> wimlib.net Git - wimlib/blobdiff - src/add_image.c
build_Dentry_tree(): Make sure capture config gets destroyed
[wimlib] / src / add_image.c
index 5b51f493ea78e597375259ee7345be6222ae98ea..ed8bae23d2a86e36774a1ed19e3c92f4847a2ec2 100644 (file)
@@ -536,6 +536,7 @@ out_find_close:
        FindClose(hFind);
        return ret;
 }
+
 #endif
 
 /*
@@ -847,7 +848,7 @@ static int build_dentry_tree(struct wim_dentry **root_ret,
        ret = utf8_to_utf16(root_disk_path, strlen(root_disk_path),
                            (char**)&path_utf16, &path_utf16_nchars);
        if (ret)
-               goto out;
+               goto out_destroy_sd_set;
        path_utf16_nchars /= sizeof(wchar_t);
 
        HANDLE hFile = win32_open_file_readonly(path_utf16);
@@ -856,7 +857,7 @@ static int build_dentry_tree(struct wim_dentry **root_ret,
                ERROR("Win32 API: Failed to open \"%s\"", root_disk_path);
                win32_error(err);
                ret = WIMLIB_ERR_OPEN;
-               goto out_destroy_sd_set;
+               goto out_free_path_utf16;
        }
 
        BY_HANDLE_FILE_INFORMATION file_info;
@@ -939,11 +940,11 @@ static int build_dentry_tree(struct wim_dentry **root_ret,
        }
 out_close_handle:
        CloseHandle(hFile);
+out_free_path_utf16:
+       FREE(path_utf16);
 out_destroy_sd_set:
        if (extra_arg == NULL)
                destroy_sd_set(sd_set);
-out_free_path_utf16:
-       FREE(path_utf16);
 #endif
        /* The below lines of code are common to both UNIX and Win32 builds.  It
         * simply returns the captured directory tree if the capture was
@@ -1544,6 +1545,11 @@ WIMLIBAPI int wimlib_add_image_multisource(WIMStruct *w,
        } else {
                size_t i;
 
+#if defined(__CYGWIN__) || defined(__WIN32__)
+               win32_acquire_privilege(SE_BACKUP_NAME);
+               win32_acquire_privilege(SE_SECURITY_NAME);
+               win32_acquire_privilege(SE_TAKE_OWNERSHIP_NAME);
+#endif
                root_dentry = NULL;
                i = 0;
                do {
@@ -1622,7 +1628,7 @@ WIMLIBAPI int wimlib_add_image_multisource(WIMStruct *w,
        if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_BOOT)
                wimlib_set_boot_idx(w, w->hdr.image_count);
        ret = 0;
-       goto out;
+       goto out_destroy_capture_config;
 out_destroy_imd:
        destroy_image_metadata(&w->image_metadata[w->hdr.image_count - 1],
                               w->lookup_table);
@@ -1637,6 +1643,11 @@ out_free_security_data:
 out_destroy_capture_config:
        destroy_capture_config(&config);
 out:
+#if defined(__CYGWIN__) || defined(__WIN32__)
+       win32_release_privilege(SE_BACKUP_NAME);
+       win32_release_privilege(SE_SECURITY_NAME);
+       win32_release_privilege(SE_TAKE_OWNERSHIP_NAME);
+#endif
        return ret;
 }