[Ocfs2-tools-devel] [PATCH 1/2 v2] o2image: 'blk' and 'ofs->ost' need to be freed when error happens in ocfs2_image_load_bitmap()
piaojun
piaojun at huawei.com
Tue Apr 3 03:58:45 PDT 2018
1. 'blk' should be freed if ocfs2_image_alloc_bitmap() failed.
2. 'ofs->ost' should be freed when ocfs2_malloc_block() failed.
Signed-off-by: Jun Piao <piaojun at huawei.com>
---
libocfs2/image.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libocfs2/image.c b/libocfs2/image.c
index 4ceab67..726d385 100644
--- a/libocfs2/image.c
+++ b/libocfs2/image.c
@@ -166,7 +166,7 @@ errcode_t ocfs2_image_load_bitmap(ocfs2_filesys *ofs)
int i, j, fd;
ssize_t count;
errcode_t ret;
- char *blk;
+ char *blk = NULL;
ret = ocfs2_malloc0(sizeof(struct ocfs2_image_state), &ofs->ost);
if (ret)
@@ -175,7 +175,7 @@ errcode_t ocfs2_image_load_bitmap(ocfs2_filesys *ofs)
ost = ofs->ost;
ret = ocfs2_malloc_block(ofs->fs_io, &blk);
if (ret)
- return ret;
+ goto out;
/* read ocfs2 image header */
ret = io_read_block(ofs->fs_io, 0, 1, blk);
@@ -204,7 +204,7 @@ errcode_t ocfs2_image_load_bitmap(ocfs2_filesys *ofs)
ret = ocfs2_image_alloc_bitmap(ofs);
if (ret)
- return ret;
+ goto out;
/* load bitmap blocks ocfs2 image state */
bits_set = 0;
@@ -235,6 +235,10 @@ errcode_t ocfs2_image_load_bitmap(ocfs2_filesys *ofs)
out:
if (blk)
ocfs2_free(&blk);
+ if (ret) {
+ ocfs2_image_free_bitmap(ofs);
+ ocfs2_free(&ofs->ost);
+ }
return ret;
}
--
More information about the Ocfs2-tools-devel
mailing list