Squashfs: add missing block release on error condition
authorPhillip Lougher <phillip@squashfs.org.uk>
Thu, 29 Dec 2011 03:50:20 +0000 (03:50 +0000)
committerPhillip Lougher <phillip@squashfs.org.uk>
Fri, 30 Dec 2011 01:20:14 +0000 (01:20 +0000)
squashfs_read_metadata forgets to release the cache block if
an error has occurred.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
fs/squashfs/cache.c

index f744be98cd5abc8dd6d93cf4a699981491f8e811..ea6e798e548b54a8698a205abb8d9dd3cb9b89df 100644 (file)
@@ -332,17 +332,20 @@ int squashfs_read_metadata(struct super_block *sb, void *buffer,
                u64 *block, int *offset, int length)
 {
        struct squashfs_sb_info *msblk = sb->s_fs_info;
-       int bytes, copied = length;
+       int bytes, res = length;
        struct squashfs_cache_entry *entry;
 
        TRACE("Entered squashfs_read_metadata [%llx:%x]\n", *block, *offset);
 
        while (length) {
                entry = squashfs_cache_get(sb, msblk->block_cache, *block, 0);
-               if (entry->error)
-                       return entry->error;
-               else if (*offset >= entry->length)
-                       return -EIO;
+               if (entry->error) {
+                       res = entry->error;
+                       goto error;
+               } else if (*offset >= entry->length) {
+                       res = -EIO;
+                       goto error;
+               }
 
                bytes = squashfs_copy_data(buffer, entry, *offset, length);
                if (buffer)
@@ -358,7 +361,11 @@ int squashfs_read_metadata(struct super_block *sb, void *buffer,
                squashfs_cache_put(entry);
        }
 
-       return copied;
+       return res;
+
+error:
+       squashfs_cache_put(entry);
+       return res;
 }