From d23e7ede0acfc2f853e6f9416a72fa5fa01a4c42 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Nov 2014 14:16:28 -0600 Subject: Fix some memeory leaks detected by cppcheck --- nuttx/tools/mkconfig.c | 1 + nuttx/tools/mkversion.c | 1 + nuttx/tools/pic32mx/mkpichex.c | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c index 8fe572825..d21930101 100644 --- a/nuttx/tools/mkconfig.c +++ b/nuttx/tools/mkconfig.c @@ -283,5 +283,6 @@ int main(int argc, char **argv, char **envp) /* Exit (without bothering to clean up allocations) */ + free(filepath); return 0; } diff --git a/nuttx/tools/mkversion.c b/nuttx/tools/mkversion.c index 2341a6c2a..1fa1ac366 100644 --- a/nuttx/tools/mkversion.c +++ b/nuttx/tools/mkversion.c @@ -105,5 +105,6 @@ int main(int argc, char **argv, char **envp) /* Exit (without bothering to clean up allocations) */ + free(filepath); return 0; } diff --git a/nuttx/tools/pic32mx/mkpichex.c b/nuttx/tools/pic32mx/mkpichex.c index a8be22cda..48cb02805 100644 --- a/nuttx/tools/pic32mx/mkpichex.c +++ b/nuttx/tools/pic32mx/mkpichex.c @@ -239,6 +239,7 @@ int main(int argc, char **argv, char **envp) char *destfile; FILE *src; FILE *dest; + int err; if (argc != 2) { @@ -257,21 +258,24 @@ int main(int argc, char **argv, char **envp) if (!destfile) { fprintf(stderr, "getfilepath failed\n"); - exit(2); + err = 2; + goto errout_with_srcfile; } src = fopen(srcfile, "r"); if (!src) { fprintf(stderr, "open %s failed: %s\n", srcfile, strerror(errno)); - exit(3); + err = 3; + goto errout_with_destfile; } dest = fopen(destfile, "w"); if (!dest) { fprintf(stderr, "open %s failed: %s\n", destfile, strerror(errno)); - exit(3); + err = 3; + goto errout_with_destfile; } /* Read each line from the source file */ @@ -281,7 +285,8 @@ int main(int argc, char **argv, char **envp) if (parse_line(&hexline)) { fprintf(stderr, "Failed to parse line\n"); - exit(1); + err = 1; + goto errout_with_destfile; } /* Adjust 'Extended Segment Address Records'. */ @@ -290,6 +295,7 @@ int main(int argc, char **argv, char **envp) { adjust_extlin(&hexline); } + fputs(line, dest); } @@ -314,4 +320,10 @@ int main(int argc, char **argv, char **envp) /* Exit (without bothering to clean up allocations) */ return 0; + +errout_with_destfile: + free(destfile); +errout_with_srcfile: + free(srcfile); + return err; } -- cgit v1.2.3