wim.c: replace finalize_wim_struct() with wim_decrement_refcnt()
authorEric Biggers <ebiggers3@gmail.com>
Wed, 25 Nov 2015 04:11:58 +0000 (22:11 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 19 Dec 2015 16:31:10 +0000 (10:31 -0600)
include/wimlib/wim.h
src/blob_table.c
src/wim.c

index 00de8a5..67f55e3 100644 (file)
@@ -186,7 +186,7 @@ static inline bool wim_is_pipable(const WIMStruct *wim)
 }
 
 extern void
 }
 
 extern void
-finalize_wim_struct(WIMStruct *wim);
+wim_decrement_refcnt(WIMStruct *wim);
 
 extern bool
 wim_has_solid_resources(const WIMStruct *wim);
 
 extern bool
 wim_has_solid_resources(const WIMStruct *wim);
index 1509a83..e1fb6ad 100644 (file)
@@ -173,9 +173,7 @@ blob_release_location(struct blob_descriptor *blob)
 
                list_del(&blob->rdesc_node);
                if (list_empty(&rdesc->blob_list)) {
 
                list_del(&blob->rdesc_node);
                if (list_empty(&rdesc->blob_list)) {
-                       wimlib_assert(rdesc->wim->refcnt > 0);
-                       if (--rdesc->wim->refcnt == 0)
-                               finalize_wim_struct(rdesc->wim);
+                       wim_decrement_refcnt(rdesc->wim);
                        FREE(rdesc);
                }
                break;
                        FREE(rdesc);
                }
                break;
index e01131d..b582717 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -867,10 +867,14 @@ can_modify_wim(WIMStruct *wim)
        return 0;
 }
 
        return 0;
 }
 
-/* Free a WIMStruct after no more resources reference it.  */
+/* Release a reference to a WIMStruct.  If the reference count reaches 0, the
+ * WIMStruct is freed.  */
 void
 void
-finalize_wim_struct(WIMStruct *wim)
+wim_decrement_refcnt(WIMStruct *wim)
 {
 {
+       wimlib_assert(wim->refcnt > 0);
+       if (--wim->refcnt != 0)
+               return;
        if (filedes_valid(&wim->in_fd))
                filedes_close(&wim->in_fd);
        if (filedes_valid(&wim->out_fd))
        if (filedes_valid(&wim->in_fd))
                filedes_close(&wim->in_fd);
        if (filedes_valid(&wim->out_fd))
@@ -901,9 +905,7 @@ wimlib_free(WIMStruct *wim)
                wim->image_metadata = NULL;
        }
 
                wim->image_metadata = NULL;
        }
 
-       wimlib_assert(wim->refcnt > 0);
-       if (--wim->refcnt == 0)
-               finalize_wim_struct(wim);
+       wim_decrement_refcnt(wim);
 }
 
 static bool
 }
 
 static bool