Index: uspace/lib/ext4/libext4_filesystem.c
===================================================================
--- uspace/lib/ext4/libext4_filesystem.c	(revision f5c03a89553e2d38dd4d8cd1f1d5a961d680d3b3)
+++ uspace/lib/ext4/libext4_filesystem.c	(revision 749fe15b74e83e98f982655fff497a808f7675f4)
@@ -53,33 +53,30 @@
     enum cache_mode cmode)
 {
+	ext4_superblock_t *temp_superblock = NULL;
+
 	fs->device = service_id;
-	
+
 	/* Initialize block library (4096 is size of communication channel) */
 	int rc = block_init(EXCHANGE_SERIALIZE, fs->device, 4096);
 	if (rc != EOK)
-		return rc;
-	
+		goto err;
+
 	/* Read superblock from device to memory */
-	ext4_superblock_t *temp_superblock;
 	rc = ext4_superblock_read_direct(fs->device, &temp_superblock);
-	if (rc != EOK) {
-		block_fini(fs->device);
-		return rc;
-	}
-	
+	if (rc != EOK)
+		goto err_1;
+
 	/* Read block size from superblock and check */
 	uint32_t block_size = ext4_superblock_get_block_size(temp_superblock);
 	if (block_size > EXT4_MAX_BLOCK_SIZE) {
-		block_fini(fs->device);
-		return ENOTSUP;
-	}
-	
+		rc = ENOTSUP;
+		goto err_1;
+	}
+
 	/* Initialize block caching by libblock */
 	rc = block_cache_init(service_id, block_size, 0, cmode);
-	if (rc != EOK) {
-		block_fini(fs->device);
-		return rc;
-	}
-	
+	if (rc != EOK)
+		goto err_1;
+
 	/* Compute limits for indirect block levels */
 	uint32_t block_ids_per_block = block_size / sizeof(uint32_t);
@@ -92,32 +89,37 @@
 		    fs->inode_blocks_per_level[i];
 	}
-	
+
 	/* Return loaded superblock */
 	fs->superblock = temp_superblock;
-	
+
 	uint16_t state = ext4_superblock_get_state(fs->superblock);
-	
+
 	if (((state & EXT4_SUPERBLOCK_STATE_VALID_FS) !=
 	    EXT4_SUPERBLOCK_STATE_VALID_FS) ||
 	    ((state & EXT4_SUPERBLOCK_STATE_ERROR_FS) ==
 	    EXT4_SUPERBLOCK_STATE_ERROR_FS)) {
-		block_cache_fini(fs->device);
-		block_fini(fs->device);
-		return ENOTSUP;
-	}
-	
+		rc = ENOTSUP;
+		goto err_2;
+	}
+
 	/* Mark system as mounted */
 	ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_ERROR_FS);
 	rc = ext4_superblock_write_direct(fs->device, fs->superblock);
-	if (rc != EOK) {
-		block_cache_fini(fs->device);
-		block_fini(fs->device);
-		return rc;
-	}
-	
+	if (rc != EOK)
+		goto err_2;
+
 	uint16_t mnt_count = ext4_superblock_get_mount_count(fs->superblock);
 	ext4_superblock_set_mount_count(fs->superblock, mnt_count + 1);
-	
+
 	return EOK;
+
+err_2:
+	block_cache_fini(fs->device);
+err_1:
+	block_fini(fs->device);
+err:
+	if (temp_superblock)
+		ext4_superblock_release(temp_superblock);
+	return rc;
 }
 
Index: uspace/lib/ext4/libext4_superblock.c
===================================================================
--- uspace/lib/ext4/libext4_superblock.c	(revision f5c03a89553e2d38dd4d8cd1f1d5a961d680d3b3)
+++ uspace/lib/ext4/libext4_superblock.c	(revision 749fe15b74e83e98f982655fff497a808f7675f4)
@@ -1178,4 +1178,14 @@
 }
 
+/** Release the memory allocated for the superblock structure
+ *
+ * @param sb         Superblock to be freed
+ *
+ */
+void ext4_superblock_release(ext4_superblock_t *sb)
+{
+	free(sb);
+}
+
 /** Check sanity of the superblock.
  *
Index: uspace/lib/ext4/libext4_superblock.h
===================================================================
--- uspace/lib/ext4/libext4_superblock.h	(revision f5c03a89553e2d38dd4d8cd1f1d5a961d680d3b3)
+++ uspace/lib/ext4/libext4_superblock.h	(revision 749fe15b74e83e98f982655fff497a808f7675f4)
@@ -145,4 +145,5 @@
 extern int ext4_superblock_read_direct(service_id_t, ext4_superblock_t **);
 extern int ext4_superblock_write_direct(service_id_t, ext4_superblock_t *);
+extern void ext4_superblock_release(ext4_superblock_t *);
 extern int ext4_superblock_check_sanity(ext4_superblock_t *);
 
