From 94fe6c80c71b0f8789aa55d2fd321d78e264b0f3 Mon Sep 17 00:00:00 2001 From: brucec Date: Wed, 23 Feb 2011 17:17:05 +0000 Subject: Handle memory allocation failures in include(). PR: i386/85652 Submitted by: Ben Thomas MFC after: 3 days --- sys/boot/common/interp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'sys/boot/common') 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; -- cgit v1.1