]> git.sur5r.net Git - openocd/commitdiff
tcl: fix potential memory leaks
authorSpencer Oliver <spen@spen-soft.co.uk>
Mon, 13 Aug 2012 10:31:54 +0000 (11:31 +0100)
committerFreddie Chopin <freddie.chopin@gmail.com>
Fri, 24 Aug 2012 16:50:18 +0000 (16:50 +0000)
Reorder to allocate all memory after COMMAND_PARSE_NUMBER call.
This removes a clang warning about un-released memory

Change-Id: I8dbeb664a6467077157015bd879bc0aefc5e8614
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/776
Tested-by: jenkins
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
src/flash/nor/tcl.c

index ec80f6ff6428f6e374c3f3ccce6b25aeb971d4cb..cf6fa080377bbb2f727d984ab35c2a175335e242 100644 (file)
@@ -427,16 +427,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
        int retval = ERROR_OK;
 
        static size_t const chunksize = 1024;
-       uint8_t *chunk = malloc(chunksize);
-       if (chunk == NULL)
-               return ERROR_FAIL;
-
-       uint8_t *readback = malloc(chunksize);
-       if (readback == NULL) {
-               free(chunk);
-               return ERROR_FAIL;
-       }
-
+       uint8_t *chunk = NULL, *readback = NULL;
 
        if (CMD_ARGC != 3) {
                retval = ERROR_COMMAND_SYNTAX_ERROR;
@@ -447,6 +438,16 @@ COMMAND_HANDLER(handle_flash_fill_command)
        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], pattern);
        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count);
 
+       chunk = malloc(chunksize);
+       if (chunk == NULL)
+               return ERROR_FAIL;
+
+       readback = malloc(chunksize);
+       if (readback == NULL) {
+               free(chunk);
+               return ERROR_FAIL;
+       }
+
        if (count == 0)
                goto done;