Skip to content

Commit

Permalink
ubifs: ubifs_add_orphan: Fix a memory leak bug
Browse files Browse the repository at this point in the history
Memory leak occurs when files with extended attributes are added to
orphan list.

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Fixes: 988bec4 ("ubifs: orphan: Handle xattrs like files")
Signed-off-by: Richard Weinberger <richard@nod.at>
  • Loading branch information
Zhihao Cheng authored and Richard Weinberger committed Mar 30, 2020
1 parent 81423c7 commit 927cc5c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions fs/ubifs/orphan.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
int err = 0;
ino_t xattr_inum;
union ubifs_key key;
struct ubifs_dent_node *xent;
struct ubifs_dent_node *xent, *pxent = NULL;
struct fscrypt_name nm = {0};
struct ubifs_orphan *xattr_orphan;
struct ubifs_orphan *orphan;
Expand All @@ -181,11 +181,16 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
xattr_inum = le64_to_cpu(xent->inum);

xattr_orphan = orphan_add(c, xattr_inum, orphan);
if (IS_ERR(xattr_orphan))
if (IS_ERR(xattr_orphan)) {
kfree(xent);
return PTR_ERR(xattr_orphan);
}

kfree(pxent);
pxent = xent;
key_read(c, &xent->key, &key);
}
kfree(pxent);

return 0;
}
Expand Down

0 comments on commit 927cc5c

Please sign in to comment.