wim_recalculate_refcnts(): Check for error
authorEric Biggers <ebiggers3@gmail.com>
Fri, 13 Dec 2013 16:11:28 +0000 (10:11 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Fri, 13 Dec 2013 16:11:28 +0000 (10:11 -0600)
include/wimlib/wim.h
src/verify.c
src/wim.c

index e972950..ee270ed 100644 (file)
@@ -102,7 +102,7 @@ static inline bool wim_has_metadata(const WIMStruct *wim)
        return (wim->image_metadata != NULL || wim->hdr.image_count == 0);
 }
 
-extern void
+extern int
 wim_recalculate_refcnts(WIMStruct *wim);
 
 extern u32
index 10db163..a9de114 100644 (file)
@@ -151,13 +151,16 @@ tally_image_refcnts(WIMStruct *wim)
  * problem by looking at ALL the images to re-calculate the reference count of
  * EVERY lookup table entry.  This only absolutely has to be done before an image
  * is deleted or before an image is mounted read-write. */
-void
+int
 wim_recalculate_refcnts(WIMStruct *wim)
 {
        unsigned long num_ltes_with_bogus_refcnt = 0;
+       int ret;
 
        for_lookup_table_entry(wim->lookup_table, lte_zero_real_refcnt, NULL);
-       for_image(wim, WIMLIB_ALL_IMAGES, tally_image_refcnts);
+       ret = for_image(wim, WIMLIB_ALL_IMAGES, tally_image_refcnts);
+       if (ret)
+               return ret;
        num_ltes_with_bogus_refcnt = 0;
        for_lookup_table_entry(wim->lookup_table, lte_fix_refcnt,
                               &num_ltes_with_bogus_refcnt);
@@ -168,4 +171,5 @@ wim_recalculate_refcnts(WIMStruct *wim)
                        num_ltes_with_bogus_refcnt);
        }
        wim->refcnts_ok = 1;
+       return 0;
 }
index 60e29b4..2f5f5e0 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -887,8 +887,11 @@ can_delete_from_wim(WIMStruct *wim)
        ret = can_modify_wim(wim);
        if (ret)
                return ret;
-       if (!wim->refcnts_ok)
-               wim_recalculate_refcnts(wim);
+       if (!wim->refcnts_ok) {
+               ret = wim_recalculate_refcnts(wim);
+               if (ret)
+                       return ret;
+       }
        return 0;
 }