[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240906091333.11419-1-zhujun2@cmss.chinamobile.com>
Date: Fri, 6 Sep 2024 02:13:33 -0700
From: Zhu Jun <zhujun2@...s.chinamobile.com>
To: decui@...rosoft.com
Cc: kys@...rosoft.com,
haiyangz@...rosoft.com,
wei.liu@...nel.org,
linux-hyperv@...r.kernel.org,
linux-kernel@...r.kernel.org,
zhujun2@...s.chinamobile.com
Subject: [PATCH v3] tools/hv: Add memory allocation check in hv_fcopy_start
Added error handling for memory allocation failures
of file_name and path_name.
Signed-off-by: Zhu Jun <zhujun2@...s.chinamobile.com>
---
v1->v2:
Add cleanup memory
v2->v3:
If we're calling exit() just 2 lines later, it doesn't make a lot of sense
to call free().
free(NULL) is valid (refer to "man 3 free").
tools/hv/hv_fcopy_uio_daemon.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/hv/hv_fcopy_uio_daemon.c b/tools/hv/hv_fcopy_uio_daemon.c
index 3ce316cc9f97..7a00f3066a98 100644
--- a/tools/hv/hv_fcopy_uio_daemon.c
+++ b/tools/hv/hv_fcopy_uio_daemon.c
@@ -296,6 +296,13 @@ static int hv_fcopy_start(struct hv_start_fcopy *smsg_in)
file_name = (char *)malloc(file_size * sizeof(char));
path_name = (char *)malloc(path_size * sizeof(char));
+ if (!file_name || !path_name) {
+ free(file_name);
+ free(path_name);
+ syslog(LOG_ERR, "Can't allocate memory for file name and/or path name");
+ return HV_E_FAIL;
+ }
+
wcstoutf8(file_name, (__u16 *)in_file_name, file_size);
wcstoutf8(path_name, (__u16 *)in_path_name, path_size);
--
2.17.1
Powered by blists - more mailing lists