diff options
author | Theron Spiegl <tspiegl@gmail.com> | 2020-06-12 18:40:17 -0500 |
---|---|---|
committer | Theron Spiegl <tspiegl@gmail.com> | 2020-06-12 18:40:17 -0500 |
commit | c0dfcbfce1cf1c2d9248a31d8173a2499baa82df (patch) | |
tree | 9723de58d9576d44a43674bfda6e391f9f80900b | |
parent | 78425842b42da83dd14c0873e75948b52eefe9f1 (diff) |
remove unnecessary null checks for free()
-rw-r--r-- | src/hashmap.c | 8 | ||||
-rw-r--r-- | src/strings.c | 2 |
2 files changed, 3 insertions, 7 deletions
diff --git a/src/hashmap.c b/src/hashmap.c index 106c65a..1e0d43e 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -93,9 +93,7 @@ HashError destroy(HashMap map) } // this loop never fired because I had map->size = 0 at the top. I'm an idiot. for (int i = 0; i < map->size; i++) { - if (map->names[i].data) { - free(map->names[i].data); - } + free(map->names[i].data); } free(map->keys); free(map->status); @@ -182,9 +180,7 @@ HashError remove_pid(pid_t pid, HashMap map) if (res == OK) { map->keys[idx] = 0; map->status[idx] = 0; - if (map->names[idx].data) { - free(map->names[idx].data); - } + free(map->names[idx].data); struct String zeroed = {0}; map->names[idx] = zeroed; map->used--; diff --git a/src/strings.c b/src/strings.c index baa433f..9df1c49 100644 --- a/src/strings.c +++ b/src/strings.c @@ -7,7 +7,7 @@ // new String pointers must be zeroed before being handed to this function void init_string(struct String *str, size_t initial_capacity) { - if (str->data) free(str->data); + free(str->data); str->data = malloc(initial_capacity); if (str->data == NULL) { perror("malloc() failed"); |