From 45552825716c8b6e05f42511eba042367efc0fb1 Mon Sep 17 00:00:00 2001 From: Bruno Herrera Date: Sun, 30 Aug 2015 18:28:04 -0600 Subject: [PATCH] apps/nshlib: Fix error handling in 'mv' command. On a failure to expand the second path, the memory allocated for the expansion of the first path was not being freed. From Bruno Herrera. --- ChangeLog.txt | 5 ++++- nshlib/nsh_fscmds.c | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 13e69aa99..81af52b7b 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1418,5 +1418,8 @@ * 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 + allocate memory, a file was not being closed. From Bruno Herrera (2015-08-26). + * apps/nshlib: Fix error handling in 'mv' command. On a failure to + expand the second path, the memory allocated for the expansion of the + first path was not being freed. From Bruno Herrera (2015-08-26). diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index 350c2c199..937b95af9 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -1348,8 +1348,8 @@ int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) newpath = nsh_getfullpath(vtbl, argv[2]); if (!newpath) { - nsh_freefullpath(newpath); - return ERROR; + ret = ERROR; + goto errout_with_free; } /* Perform the mount */ @@ -1361,7 +1361,7 @@ int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } /* Free the file paths */ - +errout_with_free: nsh_freefullpath(oldpath); nsh_freefullpath(newpath); return ret;