Author: stefanct
Date: Wed Dec 26 08:55:00 2012
New Revision: 1629
URL: http://flashrom.org/trac/flashrom/changeset/1629

Log:
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.

Signed-off-by: Stefan Tauner <[email protected]>
Acked-by: Stefan Tauner <[email protected]>

Modified:
   trunk/cli_classic.c
   trunk/flashrom.c

Modified: trunk/cli_classic.c
==============================================================================
--- trunk/cli_classic.c Mon Dec 24 23:07:36 2012        (r1628)
+++ trunk/cli_classic.c Wed Dec 26 08:55:00 2012        (r1629)
@@ -130,7 +130,9 @@
 
        char *filename = NULL;
        char *layoutfile = NULL;
+#ifndef STANDALONE
        char *logfile = NULL;
+#endif /* !STANDALONE */
        char *tempstr = NULL;
        char *pparam = NULL;
 
@@ -217,8 +219,12 @@
                        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 @@
                cli_classic_abort_usage();
        if (logfile && open_logfile(logfile))
                return 1;
+       free(logfile);
 #endif /* !STANDALONE */
 
 #if CONFIG_PRINT_WIKI == 1
@@ -473,6 +480,7 @@
                        }
                        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 @@
 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 */

Modified: trunk/flashrom.c
==============================================================================
--- trunk/flashrom.c    Mon Dec 24 23:07:36 2012        (r1628)
+++ trunk/flashrom.c    Wed Dec 26 08:55:00 2012        (r1629)
@@ -351,6 +351,7 @@
                int i = --shutdown_fn_count;
                ret |= shutdown_fn[i].func(shutdown_fn[i].data);
        }
+       programmer_param = NULL;
        return ret;
 }
 

_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to