Index: uspace/srv/fs/minixfs/mfs_dentry.c
===================================================================
--- uspace/srv/fs/minixfs/mfs_dentry.c	(revision 2527b1d5da0aa57bb2d42f4eb7fd8a180c6e9ae5)
+++ uspace/srv/fs/minixfs/mfs_dentry.c	(revision e80c2ff92c5d450f31f23c933347342b5a92628b)
@@ -36,5 +36,5 @@
 int
 read_directory_entry(struct mfs_node *mnode,
-		     struct mfs_dentry_info **d_info, unsigned index)
+		     struct mfs_dentry_info *d_info, unsigned index)
 {
 	const struct mfs_instance *inst = mnode->instance;
@@ -44,11 +44,6 @@
 	block_t *b;
 
-	*d_info = malloc(sizeof(**d_info));
-	if (!*d_info)
-		return ENOMEM;
-
 	int r = read_map(&block, mnode, index * sbi->dirsize);
-	if (r != EOK)
-		goto out_err;
+	on_error(r, goto out_err);
 
 	if (block == 0) {
@@ -59,6 +54,5 @@
 
 	r = block_get(&b, inst->handle, block, BLOCK_FLAGS_NONE);
-	if (r != EOK)
-		goto out_err;
+	on_error(r, goto out_err);
 
 	unsigned dentries_per_zone = sbi->block_size / sbi->dirsize;
@@ -70,6 +64,6 @@
 		d3 = b->data + (dentry_off * MFS3_DIRSIZE);
 
-		(*d_info)->d_inum = conv32(sbi->native, d3->d_inum);
-		memcpy((*d_info)->d_name, d3->d_name, MFS3_MAX_NAME_LEN);
+		d_info->d_inum = conv32(sbi->native, d3->d_inum);
+		memcpy(d_info->d_name, d3->d_name, MFS3_MAX_NAME_LEN);
 	} else {
 		const int namelen = longnames ? MFS_L_MAX_NAME_LEN :
@@ -80,18 +74,15 @@
 		d = b->data + dentry_off * (longnames ? MFSL_DIRSIZE :
 					    MFS_DIRSIZE);
-		(*d_info)->d_inum = conv16(sbi->native, d->d_inum);
-		memcpy((*d_info)->d_name, d->d_name, namelen);
+		d_info->d_inum = conv16(sbi->native, d->d_inum);
+		memcpy(d_info->d_name, d->d_name, namelen);
 	}
 
 	block_put(b);
 
-	(*d_info)->index = index;
-	(*d_info)->node = mnode;
+	d_info->index = index;
+	d_info->node = mnode;
+
+out_err:
 	return EOK;
-
-out_err:
-	free(*d_info);
-	*d_info = NULL;
-	return r;
 }
 
@@ -108,10 +99,8 @@
 
 	r = read_map(&block, mnode, d_off_bytes);
-	if (r != EOK)
-		goto out;
+	on_error(r, goto out);
 
 	r = block_get(&b, mnode->instance->handle, block, BLOCK_FLAGS_NONE);
-	if (r != EOK)
-		goto out;
+	on_error(r, goto out);
 
 	const size_t name_len = sbi->max_name_len;
@@ -144,6 +133,6 @@
 {
 	struct mfs_sb_info *sbi = mnode->instance->sbi;
-	struct mfs_dentry_info *d_info;
-	int i, r;
+	struct mfs_dentry_info d_info;
+	int r;
 
 	const size_t name_len = str_size(d_name);
@@ -153,20 +142,14 @@
 
 	/*Search the directory entry to be removed*/
-	for (i = 0; ; ++i) {
+	unsigned i;
+	for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize ; ++i) {
 		r = read_directory_entry(mnode, &d_info, i);
 		on_error(r, return r);
 
-		if (!d_info) {
-			/*Reached the end of the dentries list*/
-			break;
-		}
-
-		if (!bcmp(d_info->d_name, d_name, name_len)) {
-			d_info->d_inum = 0;
-			r = write_dentry(d_info);
-			free(d_info);
+		if (!bcmp(d_info.d_name, d_name, name_len)) {
+			d_info.d_inum = 0;
+			r = write_dentry(&d_info);
 			return r;
 		}
-		free(d_info);
 	}
 
@@ -177,7 +160,7 @@
 insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum)
 {
-	int i, r;
+	int r;
 	struct mfs_sb_info *sbi = mnode->instance->sbi;
-	struct mfs_dentry_info *d_info;
+	struct mfs_dentry_info d_info;
 	bool empty_dentry_found = false;
 
@@ -188,21 +171,14 @@
 
 	/*Search for an empty dentry*/
-
-	for (i = 0; ; ++i) {
+	unsigned i;
+	for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
 		r = read_directory_entry(mnode, &d_info, i);
-		if (r != EOK)
-			return r;
-
-		if (!d_info) {
-			/*Reached the end of the dentries list*/
-			break;
-		}
-
-		if (d_info->d_inum == 0) {
+		on_error(r, return r);
+
+		if (d_info.d_inum == 0) {
 			/*This entry is not used*/
 			empty_dentry_found = true;
 			break;
 		}
-		free(d_info);
 	}
 
@@ -213,14 +189,11 @@
 		r = read_directory_entry(mnode, &d_info, i);
 		on_error(r, goto out);
-
-		assert(d_info != NULL);
-	}
-
-	d_info->d_inum = d_inum;
-	memcpy(d_info->d_name, d_name, name_len);
-	d_info->d_name[name_len] = 0;
-
-	r = write_dentry(d_info);
-	free(d_info);
+	}
+
+	d_info.d_inum = d_inum;
+	memcpy(d_info.d_name, d_name, name_len);
+	d_info.d_name[name_len] = 0;
+
+	r = write_dentry(&d_info);
 out:
 	return r;
