From 321924c0a58de3e567e9427b053a3b6f3cbd7a29 Mon Sep 17 00:00:00 2001 From: Bruno Herrera Date: Sun, 30 Aug 2015 18:23:25 -0600 Subject: [PATCH] apps/nshlib: Fix error handling in 'cat' command. On a failure to allocate memory, a file was not being closed. From Bruno Herrera. --- ChangeLog.txt | 4 +++- nshlib/nsh_fscmds.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index af9eee2e9..13e69aa99 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1417,4 +1417,6 @@ initialized the network (2015-08-26). * apps/nettest: Extend test so that can be performed using the local loopback device (2015-08-26). - + * apps/nshlib: Fix error handling in 'cat' command. On a failure to + allocate memory, a file ws not being closed. From Bruno Herrera + (2015-08-26). diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index ed0c1c7a5..350c2c199 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -439,6 +439,7 @@ static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, buffer = (FAR char *)malloc(IOBUFFERSIZE); if(buffer == NULL) { + (void)close(fd); nsh_output(vtbl, g_fmtcmdfailed, cmd, "malloc", NSH_ERRNO); return ERROR; }