Fix some memeory leaks detected by cppcheck

This commit is contained in:
Gregory Nutt 2014-11-25 14:16:28 -06:00
parent 1aa528a572
commit 076d20f9c0
3 changed files with 18 additions and 4 deletions

View File

@ -283,5 +283,6 @@ int main(int argc, char **argv, char **envp)
/* Exit (without bothering to clean up allocations) */ /* Exit (without bothering to clean up allocations) */
free(filepath);
return 0; return 0;
} }

View File

@ -105,5 +105,6 @@ int main(int argc, char **argv, char **envp)
/* Exit (without bothering to clean up allocations) */ /* Exit (without bothering to clean up allocations) */
free(filepath);
return 0; return 0;
} }

View File

@ -239,6 +239,7 @@ int main(int argc, char **argv, char **envp)
char *destfile; char *destfile;
FILE *src; FILE *src;
FILE *dest; FILE *dest;
int err;
if (argc != 2) if (argc != 2)
{ {
@ -257,21 +258,24 @@ int main(int argc, char **argv, char **envp)
if (!destfile) if (!destfile)
{ {
fprintf(stderr, "getfilepath failed\n"); fprintf(stderr, "getfilepath failed\n");
exit(2); err = 2;
goto errout_with_srcfile;
} }
src = fopen(srcfile, "r"); src = fopen(srcfile, "r");
if (!src) if (!src)
{ {
fprintf(stderr, "open %s failed: %s\n", srcfile, strerror(errno)); fprintf(stderr, "open %s failed: %s\n", srcfile, strerror(errno));
exit(3); err = 3;
goto errout_with_destfile;
} }
dest = fopen(destfile, "w"); dest = fopen(destfile, "w");
if (!dest) if (!dest)
{ {
fprintf(stderr, "open %s failed: %s\n", destfile, strerror(errno)); 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 */ /* Read each line from the source file */
@ -281,7 +285,8 @@ int main(int argc, char **argv, char **envp)
if (parse_line(&hexline)) if (parse_line(&hexline))
{ {
fprintf(stderr, "Failed to parse line\n"); fprintf(stderr, "Failed to parse line\n");
exit(1); err = 1;
goto errout_with_destfile;
} }
/* Adjust 'Extended Segment Address Records'. */ /* Adjust 'Extended Segment Address Records'. */
@ -290,6 +295,7 @@ int main(int argc, char **argv, char **envp)
{ {
adjust_extlin(&hexline); adjust_extlin(&hexline);
} }
fputs(line, dest); fputs(line, dest);
} }
@ -314,4 +320,10 @@ int main(int argc, char **argv, char **envp)
/* Exit (without bothering to clean up allocations) */ /* Exit (without bothering to clean up allocations) */
return 0; return 0;
errout_with_destfile:
free(destfile);
errout_with_srcfile:
free(srcfile);
return err;
} }