summaryrefslogtreecommitdiffstats
path: root/cli_classic.c
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2012-12-26 07:55:00 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2012-12-26 07:55:00 +0000
commitb8911d6cecf5044f3e9c444e3086dd269a0279b1 (patch)
tree0fd10acc1591068806f8118e76f8c4c120783afd /cli_classic.c
parent21541a6b22c0ccbfa6b65a6c1d4a76cfd0360ca2 (diff)
downloadast2050-flashrom-b8911d6cecf5044f3e9c444e3086dd269a0279b1.zip
ast2050-flashrom-b8911d6cecf5044f3e9c444e3086dd269a0279b1.tar.gz
Fix memleaks in cli_classic.c
Frees the memory allocated for the following strings - log file name - layout file name - image file name - programmer parameter (and reset the associated global variable in flashrom.c) Also, free the flashchip structs allocated by probe_flash. The layout image names were not fixed due to the pending layout patches. These bugs were found thanks to valgrind. Corresponding to flashrom svn r1629. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Diffstat (limited to 'cli_classic.c')
-rw-r--r--cli_classic.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/cli_classic.c b/cli_classic.c
index 63565cb..dd070c5 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -130,7 +130,9 @@ int main(int argc, char *argv[])
char *filename = NULL;
char *layoutfile = NULL;
+#ifndef STANDALONE
char *logfile = NULL;
+#endif /* !STANDALONE */
char *tempstr = NULL;
char *pparam = NULL;
@@ -217,8 +219,12 @@ int main(int argc, char *argv[])
break;
case 'i':
tempstr = strdup(optarg);
- if (register_include_arg(tempstr))
+ if (register_include_arg(tempstr)) {
+ free(tempstr);
cli_classic_abort_usage();
+ }
+ /* FIXME: A pointer to the image name is saved in a static array (of size MAX_ROMLAYOUT)
+ * by register_include_arg() and needs to be freed after processing them. */
break;
case 'L':
if (++operation_specified > 1) {
@@ -337,6 +343,7 @@ int main(int argc, char *argv[])
cli_classic_abort_usage();
if (logfile && open_logfile(logfile))
return 1;
+ free(logfile);
#endif /* !STANDALONE */
#if CONFIG_PRINT_WIKI == 1
@@ -473,6 +480,7 @@ int main(int argc, char *argv[])
}
msg_cinfo("Please note that forced reads most likely contain garbage.\n");
ret = read_flash_to_file(&flashes[0], filename);
+ free(flashes[0].chip);
goto out_shutdown;
}
ret = 1;
@@ -517,6 +525,15 @@ int main(int argc, char *argv[])
out_shutdown:
programmer_shutdown();
out:
+ for (i = 0; i < chipcount; i++)
+ free(flashes[i].chip);
+
+ free(filename);
+ free(layoutfile);
+ free(pparam);
+ /* clean up global variables */
+ free(chip_to_probe);
+ chip_to_probe = NULL;
#ifndef STANDALONE
ret |= close_logfile();
#endif /* !STANDALONE */
OpenPOWER on IntegriCloud