target: avoid checking for non NULL pointer to free it
[openocd.git] / src / target / target.c
index a918b3acfb37a98f27c922daf745b17eec365ce4..fa609efdb3af350df4d5fe7c4ba100e10ff19d9b 100644 (file)
@@ -1788,10 +1788,8 @@ static void target_split_working_area(struct working_area *area, uint32_t size)
 
                /* If backup memory was allocated to this area, it has the wrong size
                 * now so free it and it will be reallocated if/when needed */
-               if (area->backup) {
-                       free(area->backup);
-                       area->backup = NULL;
-               }
+               free(area->backup);
+               area->backup = NULL;
        }
 }
 
@@ -1811,16 +1809,13 @@ static void target_merge_working_areas(struct target *target)
                        /* Remove the last */
                        struct working_area *to_be_freed = c->next;
                        c->next = c->next->next;
-                       if (to_be_freed->backup)
-                               free(to_be_freed->backup);
+                       free(to_be_freed->backup);
                        free(to_be_freed);
 
                        /* If backup memory was allocated to the remaining area, it's has
                         * the wrong size now */
-                       if (c->backup) {
-                               free(c->backup);
-                               c->backup = NULL;
-                       }
+                       free(c->backup);
+                       c->backup = NULL;
                } else {
                        c = c->next;
                }
@@ -2050,8 +2045,7 @@ static void target_destroy(struct target *target)
        if (target->type->deinit_target)
                target->type->deinit_target(target);
 
-       if (target->semihosting)
-               free(target->semihosting);
+       free(target->semihosting);
 
        jtag_unregister_event_callback(jtag_enable_callback, target);
 
@@ -5833,11 +5827,8 @@ static struct FastLoad *fastload;
 static void free_fastload(void)
 {
        if (fastload != NULL) {
-               int i;
-               for (i = 0; i < fastload_num; i++) {
-                       if (fastload[i].data)
-                               free(fastload[i].data);
-               }
+               for (int i = 0; i < fastload_num; i++)
+                       free(fastload[i].data);
                free(fastload);
                fastload = NULL;
        }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)