If realloc failed, raw was not freed and thus memory
was leaked.

Signed-off-by: Francois Berder <[email protected]>
---
 fs/erofs/data.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 95b609d8ea8..b58ec6fcc66 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -319,12 +319,15 @@ static int z_erofs_read_data(struct erofs_inode *inode, 
char *buffer,
                }
 
                if (map.m_plen > bufsize) {
+                       char *tmp;
+
                        bufsize = map.m_plen;
-                       raw = realloc(raw, bufsize);
-                       if (!raw) {
+                       tmp = realloc(raw, bufsize);
+                       if (!tmp) {
                                ret = -ENOMEM;
                                break;
                        }
+                       raw = tmp;
                }
 
                ret = z_erofs_read_one_data(inode, &map, raw,
-- 
2.43.0


Reply via email to