[PATCH 2/3] db: avoid to use NULL pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Changed malloc to xmalloc.

Signed-off-by: zhanchengbin <zhanchengbin1@xxxxxxxxxx>
---
 db/block.c | 2 +-
 db/check.c | 4 ++--
 db/faddr.c | 6 +++---
 db/namei.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/db/block.c b/db/block.c
index f31f9544..349cf6ec 100644
--- a/db/block.c
+++ b/db/block.c
@@ -180,7 +180,7 @@ dblock_f(
 		return 0;
 	}
 	nex = nb = type == TYP_DIR2 ? mp->m_dir_geo->fsbcount : 1;
-	bmp = malloc(nb * sizeof(*bmp));
+	bmp = xmalloc(nb * sizeof(*bmp));
 	bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
 	if (nex == 0) {
 		dbprintf(_("file data block is unmapped\n"));
diff --git a/db/check.c b/db/check.c
index a9c6e632..cc3c7832 100644
--- a/db/check.c
+++ b/db/check.c
@@ -1782,7 +1782,7 @@ dir_hash_add(
 	dirhash_t		*p;

 	i = DIR_HASH_FUNC(hash, addr);
-	p = malloc(sizeof(*p));
+	p = xmalloc(sizeof(*p));
 	p->next = dirhash[i];
 	dirhash[i] = p;
 	p->hashval = hash;
@@ -3094,7 +3094,7 @@ process_leaf_node_dir_v2(
 	v2 = verbose || id->ilist;
 	v = parent = 0;
 	dbno = NULLFILEOFF;
-	freetab = malloc(FREETAB_SIZE(dirsize / mp->m_dir_geo->blksize));
+	freetab = xmalloc(FREETAB_SIZE(dirsize / mp->m_dir_geo->blksize));
 	freetab->naents = (int)(dirsize / mp->m_dir_geo->blksize);
 	freetab->nents = 0;
 	for (i = 0; i < freetab->naents; i++)
diff --git a/db/faddr.c b/db/faddr.c
index 0127c5d1..cc21faaf 100644
--- a/db/faddr.c
+++ b/db/faddr.c
@@ -137,7 +137,7 @@ fa_cfileoffd(
 		return;
 	}
 	nex = nb = next == TYP_DIR2 ? mp->m_dir_geo->fsbcount : 1;
-	bmp = malloc(nb * sizeof(*bmp));
+	bmp = xmalloc(nb * sizeof(*bmp));
 	bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
 	if (nex == 0) {
 		dbprintf(_("file block is unmapped\n"));
@@ -221,7 +221,7 @@ fa_dfiloffd(
 		return;
 	}
 	nex = nb = next == TYP_DIR2 ? mp->m_dir_geo->fsbcount : 1;
-	bmp = malloc(nb * sizeof(*bmp));
+	bmp = xmalloc(nb * sizeof(*bmp));
 	bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
 	if (nex == 0) {
 		dbprintf(_("file block is unmapped\n"));
@@ -274,7 +274,7 @@ fa_dirblock(
 		return;
 	}
 	nex = mp->m_dir_geo->fsbcount;
-	bmp = malloc(nex * sizeof(*bmp));
+	bmp = xmalloc(nex * sizeof(*bmp));
 	bmap(bno, mp->m_dir_geo->fsbcount, XFS_DATA_FORK, &nex, bmp);
 	if (nex == 0) {
 		dbprintf(_("directory block is unmapped\n"));
diff --git a/db/namei.c b/db/namei.c
index e44667a9..d1a9904b 100644
--- a/db/namei.c
+++ b/db/namei.c
@@ -266,7 +266,7 @@ dir_emit(
 		 * copy the string to a buffer so that we can add the null
 		 * terminator.
 		 */
-		display_name = malloc(namelen + 1);
+		display_name = xmalloc(namelen + 1);
 		memcpy(display_name, name, namelen);
 		display_name[namelen] = 0;
 		xname.len = namelen;
--
2.27.0




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux