summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-11-25 14:16:28 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-11-25 14:16:28 -0600
commitd23e7ede0acfc2f853e6f9416a72fa5fa01a4c42 (patch)
treeefdf68b058903e836325d06a013f04bd5b8394ef
parente814f226d6aa6c1700706bb8db9c190b8244eee5 (diff)
downloadnuttx-d23e7ede0acfc2f853e6f9416a72fa5fa01a4c42.tar.gz
nuttx-d23e7ede0acfc2f853e6f9416a72fa5fa01a4c42.tar.bz2
nuttx-d23e7ede0acfc2f853e6f9416a72fa5fa01a4c42.zip
Fix some memeory leaks detected by cppcheck
-rw-r--r--nuttx/tools/mkconfig.c1
-rw-r--r--nuttx/tools/mkversion.c1
-rw-r--r--nuttx/tools/pic32mx/mkpichex.c20
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;
}