* [PATCH] console: use regular malloc for log messages
@ 2015-05-13 6:23 Sascha Hauer
0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2015-05-13 6:23 UTC (permalink / raw)
To: Barebox List
Using xfunctions to allocate log messages is not a good idea. Should
we be out of memory the xfunctions will panic which will cause another
allocation, so we deadlock the system with no message going out.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/console_common.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/common/console_common.c b/common/console_common.c
index 41a6929..36bd1dd 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -106,15 +106,23 @@ static void pr_puts(int level, const char *str)
log_clean(barebox_log_max_messages - 1);
if (barebox_log_max_messages >= 0) {
- log = xzalloc(sizeof(*log));
- log->msg = xstrdup(str);
+ log = malloc(sizeof(*log));
+ if (!log)
+ goto nolog;
+
+ log->msg = strdup(str);
+ if (!log->msg) {
+ free(log);
+ goto nolog;
+ }
+
log->timestamp = get_time_ns();
log->level = level;
list_add_tail(&log->list, &barebox_logbuf);
barebox_logbuf_num_messages++;
}
}
-
+nolog:
if (level > barebox_loglevel)
return;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-05-13 6:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 6:23 [PATCH] console: use regular malloc for log messages Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox