From mboxrd@z Thu Jan 1 00:00:00 1970 From: Scott Wood Date: Fri, 15 Jan 2010 16:28:48 -0600 Subject: [U-Boot] [PATCH 8/9] env_nand.c: print error message and fail gracefully In-Reply-To: <1263357841-5100-9-git-send-email-jcrigby@gmail.com> References: <1263357841-5100-1-git-send-email-jcrigby@gmail.com> <1263357841-5100-2-git-send-email-jcrigby@gmail.com> <1263357841-5100-3-git-send-email-jcrigby@gmail.com> <1263357841-5100-4-git-send-email-jcrigby@gmail.com> <1263357841-5100-5-git-send-email-jcrigby@gmail.com> <1263357841-5100-6-git-send-email-jcrigby@gmail.com> <1263357841-5100-7-git-send-email-jcrigby@gmail.com> <1263357841-5100-8-git-send-email-jcrigby@gmail.com> <1263357841-5100-9-git-send-email-jcrigby@gmail.com> Message-ID: <20100115222848.GA2932@loki.buserror.net> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Tue, Jan 12, 2010 at 09:44:00PM -0700, John Rigby wrote: > From: Wolfgang Denk > > 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 files changed, 9 insertions(+), 0 deletions(-) > > diff --git a/common/env_nand.c b/common/env_nand.c > index ca631af..a5166cb 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); No need to check for NULL; free(NULL) is a no-op. I'm also a bit concerned about bloat if we put a unique string at every potential allocation failure. -Scott