From 73e49e39dbc3943334a83a4ddda74438031bf574 Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Tue, 5 Jan 2010 22:34:17 -0700 Subject: [PATCH] env_nand.c: print error message and fail gracefully env_nand.c would crash silently if a malloc() for the environment buffers failed; make it print an error message and fail gracefully, i. e. use the default environment then. Signed-off-by: Wolfgang Denk --- common/env_nand.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/env_nand.c b/common/env_nand.c index ca631af195..a5166cbe8d 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -298,6 +298,15 @@ void env_relocate_spec (void) tmp_env1 = (env_t *) malloc(CONFIG_ENV_SIZE); tmp_env2 = (env_t *) malloc(CONFIG_ENV_SIZE); + if ((tmp_env1 == NULL) || (tmp_env2 == NULL)) { + puts("Can't allocate buffers for environment\n"); + if (tmp_env1) + free (tmp_env1); + if (tmp_env2) + free (tmp_env2); + return use_default(); + } + if (readenv(CONFIG_ENV_OFFSET, (u_char *) tmp_env1)) puts("No Valid Environment Area Found\n"); if (readenv(CONFIG_ENV_OFFSET_REDUND, (u_char *) tmp_env2)) -- 2.39.5