linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] erofs-utils: complete missing memory handling
@ 2019-11-12 11:26 Gao Xiang
  2019-11-12 11:26 ` [PATCH 2/2] erofs-utils: set up all compiler/linker variables independently Gao Xiang
  2019-11-13 17:03 ` [PATCH v2] erofs-utils: complete missing memory handling Li Guifu
  0 siblings, 2 replies; 10+ messages in thread
From: Gao Xiang @ 2019-11-12 11:26 UTC (permalink / raw)
  To: Li Guifu, Chao Yu; +Cc: Miao Xie, linux-erofs

From: Li Guifu <bluce.liguifu@huawei.com>

memory allocation failure should be handled
properly in principle.

Signed-off-by: Li Guifu <bluce.liguifu@huawei.com>
[ Gao Xiang: due to Huawei outgoing email limitation,
  I have to help Guifu send out his patches at work. ]
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
 lib/inode.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/inode.c b/lib/inode.c
index 86c465ee2f78..620db60f4a5b 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -264,6 +264,8 @@ int erofs_write_dir_file(struct erofs_inode *dir)
 	if (used) {
 		/* fill tail-end dir block */
 		dir->idata = malloc(used);
+		if (!dir->idata)
+			return -ENOMEM;
 		DBG_BUGON(used != dir->idata_size);
 		fill_dirblock(dir->idata, dir->idata_size, q, head, d);
 	}
@@ -286,6 +288,8 @@ int erofs_write_file_from_buffer(struct erofs_inode *inode, char *buf)
 	inode->idata_size = inode->i_size % EROFS_BLKSIZ;
 	if (inode->idata_size) {
 		inode->idata = malloc(inode->idata_size);
+		if (!inode->idata)
+			return -ENOMEM;
 		memcpy(inode->idata, buf + blknr_to_addr(nblocks),
 		       inode->idata_size);
 	}
@@ -347,9 +351,12 @@ int erofs_write_file(struct erofs_inode *inode)
 	inode->idata_size = inode->i_size % EROFS_BLKSIZ;
 	if (inode->idata_size) {
 		inode->idata = malloc(inode->idata_size);
+		if (!inode->idata)
+			return -ENOMEM;
 
 		ret = read(fd, inode->idata, inode->idata_size);
 		if (ret < inode->idata_size) {
+			free(inode->idata);
 			close(fd);
 			return -EIO;
 		}
@@ -825,12 +832,18 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
 		if (S_ISLNK(dir->i_mode)) {
 			char *const symlink = malloc(dir->i_size);
 
+			if (!symlink)
+				return ERR_PTR(-ENOMEM);
 			ret = readlink(dir->i_srcpath, symlink, dir->i_size);
-			if (ret < 0)
+			if (ret < 0) {
+				free(symlink);
 				return ERR_PTR(-errno);
+			}
 
-			erofs_write_file_from_buffer(dir, symlink);
+			ret = erofs_write_file_from_buffer(dir, symlink);
 			free(symlink);
+			if (ret)
+				return ERR_PTR(ret);
 		} else {
 			erofs_write_file(dir);
 		}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-11-14 15:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12 11:26 [PATCH 1/2] erofs-utils: complete missing memory handling Gao Xiang
2019-11-12 11:26 ` [PATCH 2/2] erofs-utils: set up all compiler/linker variables independently Gao Xiang
2019-11-13 17:12   ` Li Guifu
2019-11-14  0:26     ` Gao Xiang via Linux-erofs
2019-11-14 13:45       ` [PATCH v2] " Gao Xiang via Linux-erofs
2019-11-14 15:27         ` Li Guifu
2019-11-13 17:03 ` [PATCH v2] erofs-utils: complete missing memory handling Li Guifu
2019-11-14  0:24   ` Gao Xiang via Linux-erofs
2019-11-14  1:51     ` Gao Xiang
2019-11-14  9:19   ` [PATCH v3] " Gao Xiang via Linux-erofs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).