Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ubifs: Fix memory leak on error condition

If the call to ubifs_read_nnode() fails in ubifs_lpt_calc_hash() an
error is returned without freeing the memory allocated to 'buf'.
Read and check the root node before allocating the buffer.

Detected by CoverityScan, CID 1441025 ("Resource leak")

Signed-off-by: Garry McNulty <garrmcnu@gmail.com>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Garry McNulty and committed by
Richard Weinberger
6554a56f 60eb5da2

+6 -6
+6 -6
fs/ubifs/lpt.c
··· 1675 1675 if (!ubifs_authenticated(c)) 1676 1676 return 0; 1677 1677 1678 + if (!c->nroot) { 1679 + err = ubifs_read_nnode(c, NULL, 0); 1680 + if (err) 1681 + return err; 1682 + } 1683 + 1678 1684 desc = ubifs_hash_get_desc(c); 1679 1685 if (IS_ERR(desc)) 1680 1686 return PTR_ERR(desc); ··· 1689 1683 if (!buf) { 1690 1684 err = -ENOMEM; 1691 1685 goto out; 1692 - } 1693 - 1694 - if (!c->nroot) { 1695 - err = ubifs_read_nnode(c, NULL, 0); 1696 - if (err) 1697 - return err; 1698 1686 } 1699 1687 1700 1688 cnode = (struct ubifs_cnode *)c->nroot;