summaryrefslogtreecommitdiffstats
path: root/sys/boot/common/interp.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/boot/common/interp.c')
-rw-r--r--sys/boot/common/interp.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/sys/boot/common/interp.c b/sys/boot/common/interp.c
index b9343a6..a9370d9 100644
--- a/sys/boot/common/interp.c
+++ b/sys/boot/common/interp.c
@@ -246,6 +246,17 @@ include(const char *filename)
if (*cp == '\0')
continue; /* ignore empty line, save memory */
sp = malloc(sizeof(struct includeline) + strlen(cp) + 1);
+ /* On malloc failure (it happens!), free as much as possible and exit */
+ if (sp == NULL) {
+ while (script != NULL) {
+ se = script;
+ script = script->next;
+ free(se);
+ }
+ sprintf(command_errbuf, "file '%s' line %d: memory allocation "
+ "failure - aborting\n", filename, line);
+ return (CMD_ERROR);
+ }
strcpy(sp->text, cp);
#ifndef BOOT_FORTH
sp->flags = flags;
OpenPOWER on IntegriCloud