diff options
author | Garry McNulty <garrmcnu@gmail.com> | 2018-11-15 17:25:58 -0500 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2018-12-13 16:09:13 -0500 |
commit | 6554a56f352ee2a6ce295fcfb39889eb9ecc79cf (patch) | |
tree | 7036b37a474b831f003cfd1093d579d10d8c041d /fs/ubifs/lpt.c | |
parent | 60eb5da2434b5288291aac533fb4dadc8ec8aed7 (diff) |
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>
Diffstat (limited to 'fs/ubifs/lpt.c')
-rw-r--r-- | fs/ubifs/lpt.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c index d1d5e96350dd..b0c5f06128b5 100644 --- a/fs/ubifs/lpt.c +++ b/fs/ubifs/lpt.c | |||
@@ -1675,6 +1675,12 @@ int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash) | |||
1675 | if (!ubifs_authenticated(c)) | 1675 | if (!ubifs_authenticated(c)) |
1676 | return 0; | 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 | desc = ubifs_hash_get_desc(c); | 1684 | desc = ubifs_hash_get_desc(c); |
1679 | if (IS_ERR(desc)) | 1685 | if (IS_ERR(desc)) |
1680 | return PTR_ERR(desc); | 1686 | return PTR_ERR(desc); |
@@ -1685,12 +1691,6 @@ int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash) | |||
1685 | goto out; | 1691 | goto out; |
1686 | } | 1692 | } |
1687 | 1693 | ||
1688 | if (!c->nroot) { | ||
1689 | err = ubifs_read_nnode(c, NULL, 0); | ||
1690 | if (err) | ||
1691 | return err; | ||
1692 | } | ||
1693 | |||
1694 | cnode = (struct ubifs_cnode *)c->nroot; | 1694 | cnode = (struct ubifs_cnode *)c->nroot; |
1695 | 1695 | ||
1696 | while (cnode) { | 1696 | while (cnode) { |