[Ocfs2-tools-devel] [PATCH] libocfs2/alloc.c: initiate pointers to NULL for ocfs2_free()

Coly Li coly.li at suse.de
Fri Dec 25 08:56:59 PST 2009


This patch initiates pointers to NULL, to avoid SIGSEG of ocfs2_free(),  if ocfs2_malloc_block() returns error.

Signed-off-by: Coly Li <coly.li at suse.de>
---
 libocfs2/alloc.c |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/libocfs2/alloc.c b/libocfs2/alloc.c
index e076bc5..8415c06 100644
--- a/libocfs2/alloc.c
+++ b/libocfs2/alloc.c
@@ -219,7 +219,7 @@ static void ocfs2_init_eb(ocfs2_filesys *fs,
 errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *ino, int mode)
 {
 	errcode_t ret;
-	char *buf;
+	char *buf = NULL;
 	uint64_t gd_blkno;
 	struct ocfs2_dinode *di;

@@ -254,7 +254,8 @@ errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *ino, int mode)
 		ocfs2_delete_inode(fs, *ino);

 out:
-	ocfs2_free(&buf);
+	if (buf)
+		ocfs2_free(&buf);

 	return ret;
 }
@@ -263,7 +264,7 @@ errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino,
 				 int mode, int flags)
 {
 	errcode_t ret;
-	char *buf;
+	char *buf = NULL;
 	uint64_t gd_blkno;
 	struct ocfs2_dinode *di;

@@ -296,7 +297,8 @@ errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino,
 	ret = ocfs2_write_inode(fs, *ino, buf);

 out:
-	ocfs2_free(&buf);
+	if (buf)
+		ocfs2_free(&buf);

 	return ret;
 }
@@ -304,7 +306,7 @@ out:
 errcode_t ocfs2_delete_inode(ocfs2_filesys *fs, uint64_t ino)
 {
 	errcode_t ret;
-	char *buf;
+	char *buf = NULL;
 	struct ocfs2_dinode *di;
 	int16_t slot;
 	ocfs2_cached_inode **inode_alloc;
@@ -341,7 +343,8 @@ errcode_t ocfs2_delete_inode(ocfs2_filesys *fs, uint64_t ino)
 	ret = ocfs2_write_inode(fs, di->i_blkno, buf);

 out:
-	ocfs2_free(&buf);
+	if (buf)
+		ocfs2_free(&buf);

 	return ret;
 }
@@ -378,7 +381,7 @@ errcode_t ocfs2_test_inode_allocated(ocfs2_filesys *fs, uint64_t blkno,
 errcode_t ocfs2_new_extent_block(ocfs2_filesys *fs, uint64_t *blkno)
 {
 	errcode_t ret;
-	char *buf;
+	char *buf = NULL;
 	uint64_t gd_blkno;
 	struct ocfs2_extent_block *eb;

@@ -411,7 +414,8 @@ errcode_t ocfs2_new_extent_block(ocfs2_filesys *fs, uint64_t *blkno)
 	ret = ocfs2_write_extent_block(fs, *blkno, buf);

 out:
-	ocfs2_free(&buf);
+	if (buf)
+		ocfs2_free(&buf);

 	return ret;
 }
@@ -419,7 +423,7 @@ out:
 errcode_t ocfs2_delete_xattr_block(ocfs2_filesys *fs, uint64_t blkno)
 {
 	errcode_t ret;
-	char *buf;
+	char *buf = NULL;
 	int slot;
 	struct ocfs2_xattr_block *xb = NULL;

@@ -444,7 +448,8 @@ errcode_t ocfs2_delete_xattr_block(ocfs2_filesys *fs, uint64_t blkno)
 		goto out;

 out:
-	ocfs2_free(&buf);
+	if (buf)
+		ocfs2_free(&buf);

 	return ret;
 }
@@ -452,7 +457,7 @@ out:
 errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno)
 {
 	errcode_t ret;
-	char *buf;
+	char *buf = NULL;
 	struct ocfs2_extent_block *eb;
 	int slot;

@@ -478,7 +483,8 @@ errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno)
 	ret = ocfs2_write_extent_block(fs, eb->h_blkno, buf);

 out:
-	ocfs2_free(&buf);
+	if (buf)
+		ocfs2_free(&buf);

 	return ret;
 }
@@ -639,7 +645,7 @@ int main(int argc, char *argv[])
 {
 	errcode_t ret;
 	ocfs2_filesys *fs;
-	char *buf;
+	char *buf = NULL;
 	struct ocfs2_dinode *di;
 	uint64_t blkno;

@@ -681,7 +687,8 @@ int main(int argc, char *argv[])
 	}

 out_free:
-	ocfs2_free(&buf);
+	if (buf)
+		ocfs2_free(&buf);

 out_close:
 	ret = ocfs2_close(fs);
-- 
Coly Li
SuSE Labs



More information about the Ocfs2-tools-devel mailing list