erofs-utils: misc: Fix potential memory leak in realloc failure path
authorSandeep Dhavale <dhavale@google.com>
Thu, 18 Jul 2024 20:22:04 +0000 (13:22 -0700)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 19 Jul 2024 08:52:28 +0000 (16:52 +0800)
commita3a75f7af7b2fea8db29af5fd473a0246cacbc23
tree59f7257dfa7c9e2f6d1e1c6ef8f685afe29d6f56
parentb77023fda8aaa25e165da3f9ccc7acb0a497aa9a
erofs-utils: misc: Fix potential memory leak in realloc failure path

As realloc returns NULL on failure, the original value will be
overwritten if it is used as lvalue. Fix this by using a temporary
variable to hold the return value and exit with -ENOMEM in case of
failure. This patch fixes 2 of the realloc blocks with similar fix.

Signed-off-by: Sandeep Dhavale <dhavale@google.com>
Link: https://lore.kernel.org/r/20240718202204.1224620-1-dhavale@google.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
fsck/main.c
lib/data.c