linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtla/utils: Fix the potential memory allocation failure
@ 2022-06-14  9:38 jianchunfu
  2022-06-14 12:44 ` Daniel Bristot de Oliveira
  0 siblings, 1 reply; 2+ messages in thread
From: jianchunfu @ 2022-06-14  9:38 UTC (permalink / raw)
  To: bristot, rostedt; +Cc: linux-trace-devel, jianchunfu

Add memory allocating check of mon_cpus before used in utils.

Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
---
 tools/tracing/rtla/src/utils.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index ffaf8ec84..2a86440b3 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -106,6 +106,10 @@ int parse_cpu_list(char *cpu_list, char **monitored_cpus)
 	nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
 
 	mon_cpus = malloc(nr_cpus * sizeof(char));
+	if (!mon_cpus) {
+		perror("Failed to allocate memory");
+		return -errno;
+	}
 	memset(mon_cpus, 0, (nr_cpus * sizeof(char)));
 
 	for (p = cpu_list; *p; ) {
-- 
2.18.4




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

end of thread, other threads:[~2022-06-14 12:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-14  9:38 [PATCH] rtla/utils: Fix the potential memory allocation failure jianchunfu
2022-06-14 12:44 ` Daniel Bristot de Oliveira

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).