Index: uspace/lib/ext4/src/ops.c
===================================================================
--- uspace/lib/ext4/src/ops.c	(revision f62c901cedddc0f126df491f8b76d51aa9377ed9)
+++ uspace/lib/ext4/src/ops.c	(revision c182c346239ea329968605cbfc492c718b05665c)
@@ -65,5 +65,5 @@
 static errno_t ext4_instance_get(service_id_t, ext4_instance_t **);
 static errno_t handle_sparse_or_unallocated_fblock(ext4_filesystem_t *,
-    ext4_inode_ref_t *, uint32_t, uint32_t, uint32_t *, int *);
+    ext4_inode_ref_t *, uint32_t, uint32_t, uint32_t *, int *, bool *);
 
 /* Forward declarations of ext4 libfs operations. */
@@ -1288,4 +1288,6 @@
 	fs_node_t *fn;
 	errno_t rc2;
+	bool fblock_allocated = false;
+
 	errno_t rc = ext4_node_get(&fn, service_id, index);
 	if (rc != EOK)
@@ -1327,5 +1329,5 @@
 	if (fblock == 0) {
 		rc = handle_sparse_or_unallocated_fblock(fs, inode_ref,
-		    block_size, iblock, &fblock, &flags);
+		    block_size, iblock, &fblock, &flags, &fblock_allocated);
 		if (rc != EOK) {
 			async_answer_0(&call, rc);
@@ -1370,4 +1372,7 @@
 
 exit:
+	if (rc != EOK && fblock_allocated)
+		ext4_balloc_free_block(inode_ref, fblock);
+
 	rc2 = ext4_node_put(fn);
 	return rc == EOK ? rc2 : rc;
@@ -1382,4 +1387,5 @@
  * @param fblock	Place to store allocated block address
  * @param flags		BLOCK_FLAGS to update
+ * @param allocated	Place to store whether new block was allocated
  *
  * @return Error code
@@ -1388,5 +1394,5 @@
 static errno_t handle_sparse_or_unallocated_fblock(ext4_filesystem_t *fs,
     ext4_inode_ref_t *inode_ref, uint32_t block_size, uint32_t iblock,
-    uint32_t *fblock, int *flags)
+    uint32_t *fblock, int *flags, bool *allocated)
 {
 	errno_t rc;
@@ -1411,4 +1417,6 @@
 		if (rc != EOK)
 			return rc;
+
+		*allocated = false;
 	} else { /* Allocate new block */
 		rc = ext4_balloc_alloc_block(inode_ref, fblock);
@@ -1422,4 +1430,6 @@
 			return rc;
 		}
+
+		*allocated = true;
 	}
 
