From c5baa0edc4a70c2f44cb7422e2b47ab5c96570ed Mon Sep 17 00:00:00 2001 From: Krzysztof Halasa Date: Thu, 6 Jan 2011 16:23:01 +0100 Subject: Fix error handling with malloc, memalign etc. Introduce xmemalign(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The idea is to panic() when there is no memory available for normal operation. Exception: code which can consume arbitrary amount of RAM (example: files allocated in ramfs) must report error instead of panic(). This patch also fixes code which didn't check for NULL from malloc() etc. Usage: malloc(), memalign() return NULL when out of RAM. xmalloc(), xmemalign() always return non-NULL or panic(). Signed-off-by: Krzysztof HaƂasa Signed-off-by: Sascha Hauer --- scripts/basic/docproc.c | 7 +++++-- scripts/mod/modpost.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c index 0d4f5e7d74..9f6535d18f 100644 --- a/scripts/basic/docproc.c +++ b/scripts/basic/docproc.c @@ -122,8 +122,11 @@ int symfilecnt = 0; void add_new_symbol(struct symfile *sym, char * symname) { - sym->symbollist = - realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *)); + sym->symbollist = realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *)); + if (!sym->symbollist) { + fprintf(stderr, "docproc: out of memory\n"); + exit(1); + } sym->symbollist[sym->symbolcnt++].name = strdup(symname); } diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 4075c35d37..08b75b67f1 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1317,7 +1317,7 @@ void buf_write(struct buffer *buf, const char *s, int len) { if (buf->size - buf->pos < len) { buf->size += len + SZ; - buf->p = realloc(buf->p, buf->size); + buf->p = NOFAIL(realloc(buf->p, buf->size)); } strncpy(buf->p + buf->pos, s, len); buf->pos += len; -- cgit v1.2.3