diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-02-25 21:18:13 +0100 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-02-26 00:00:46 +0100 |
commit | 0a22ddfbb16a61c3e068ea1164e885104366112a (patch) | |
tree | 5aeaef43b3de5ebbdfcf1015421eb48b51a071fb /lib | |
parent | lib: STAILQ_FOREACH_SAFE never gives a null elem (diff) | |
download | frr-0a22ddfbb16a61c3e068ea1164e885104366112a.tar.xz frr-0a22ddfbb16a61c3e068ea1164e885104366112a.zip |
*: remove null check before XFREE
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/command.c | 45 | ||||
-rw-r--r-- | lib/distribute.c | 27 | ||||
-rw-r--r-- | lib/filter.c | 6 | ||||
-rw-r--r-- | lib/frr_pthread.c | 3 | ||||
-rw-r--r-- | lib/hash.c | 3 | ||||
-rw-r--r-- | lib/if.c | 12 | ||||
-rw-r--r-- | lib/if_rmap.c | 23 | ||||
-rw-r--r-- | lib/keychain.c | 6 | ||||
-rw-r--r-- | lib/log.c | 6 | ||||
-rw-r--r-- | lib/module.c | 3 | ||||
-rw-r--r-- | lib/netns_linux.c | 3 | ||||
-rw-r--r-- | lib/nexthop_group.c | 6 | ||||
-rw-r--r-- | lib/plist.c | 6 | ||||
-rw-r--r-- | lib/prefix.c | 3 | ||||
-rw-r--r-- | lib/routemap.c | 15 | ||||
-rw-r--r-- | lib/thread.c | 6 | ||||
-rw-r--r-- | lib/vty.c | 21 |
17 files changed, 67 insertions, 127 deletions
diff --git a/lib/command.c b/lib/command.c index b46241ac8..559457c11 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1277,8 +1277,7 @@ int cmd_execute(struct vty *vty, const char *cmd, hook_call(cmd_execute_done, vty, cmd_exec); - if (cmd_out) - XFREE(MTYPE_TMP, cmd_out); + XFREE(MTYPE_TMP, cmd_out); return ret; } @@ -2408,8 +2407,7 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel) ret = zlog_set_file(fullpath, loglevel); - if (p) - XFREE(MTYPE_TMP, p); + XFREE(MTYPE_TMP, p); if (!ret) { if (vty) @@ -2417,8 +2415,7 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel) return CMD_WARNING_CONFIG_FAILED; } - if (host.logfile) - XFREE(MTYPE_HOST, host.logfile); + XFREE(MTYPE_HOST, host.logfile); host.logfile = XSTRDUP(MTYPE_HOST, fname); @@ -2487,8 +2484,7 @@ static void disable_log_file(void) { zlog_reset_file(); - if (host.logfile) - XFREE(MTYPE_HOST, host.logfile); + XFREE(MTYPE_HOST, host.logfile); host.logfile = NULL; } @@ -2637,8 +2633,7 @@ int cmd_banner_motd_file(const char *file) return CMD_ERR_NO_FILE; in = strstr(rpath, SYSCONFDIR); if (in == rpath) { - if (host.motdfile) - XFREE(MTYPE_HOST, host.motdfile); + XFREE(MTYPE_HOST, host.motdfile); host.motdfile = XSTRDUP(MTYPE_HOST, file); } else success = CMD_WARNING_CONFIG_FAILED; @@ -2723,8 +2718,7 @@ DEFUN(find, /* Set config filename. Called from vty.c */ void host_config_set(const char *filename) { - if (host.config) - XFREE(MTYPE_HOST, host.config); + XFREE(MTYPE_HOST, host.config); host.config = XSTRDUP(MTYPE_HOST, filename); } @@ -2904,24 +2898,15 @@ void cmd_terminate(void) cmdvec = NULL; } - if (host.name) - XFREE(MTYPE_HOST, host.name); - if (host.domainname) - XFREE(MTYPE_HOST, host.domainname); - if (host.password) - XFREE(MTYPE_HOST, host.password); - if (host.password_encrypt) - XFREE(MTYPE_HOST, host.password_encrypt); - if (host.enable) - XFREE(MTYPE_HOST, host.enable); - if (host.enable_encrypt) - XFREE(MTYPE_HOST, host.enable_encrypt); - if (host.logfile) - XFREE(MTYPE_HOST, host.logfile); - if (host.motdfile) - XFREE(MTYPE_HOST, host.motdfile); - if (host.config) - XFREE(MTYPE_HOST, host.config); + XFREE(MTYPE_HOST, host.name); + XFREE(MTYPE_HOST, host.domainname); + XFREE(MTYPE_HOST, host.password); + XFREE(MTYPE_HOST, host.password_encrypt); + XFREE(MTYPE_HOST, host.enable); + XFREE(MTYPE_HOST, host.enable_encrypt); + XFREE(MTYPE_HOST, host.logfile); + XFREE(MTYPE_HOST, host.motdfile); + XFREE(MTYPE_HOST, host.config); list_delete(&varhandlers); qobj_finish(); diff --git a/lib/distribute.c b/lib/distribute.c index 7cc10a230..fa8ac5242 100644 --- a/lib/distribute.c +++ b/lib/distribute.c @@ -44,16 +44,15 @@ static void distribute_free(struct distribute *dist) { int i = 0; - if (dist->ifname) - XFREE(MTYPE_DISTRIBUTE_IFNAME, dist->ifname); + XFREE(MTYPE_DISTRIBUTE_IFNAME, dist->ifname); - for (i = 0; i < DISTRIBUTE_MAX; i++) - if (dist->list[i]) - XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[i]); + for (i = 0; i < DISTRIBUTE_MAX; i++) { + XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[i]); + } - for (i = 0; i < DISTRIBUTE_MAX; i++) - if (dist->prefix[i]) - XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[i]); + for (i = 0; i < DISTRIBUTE_MAX; i++) { + XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[i]); + } XFREE(MTYPE_DISTRIBUTE, dist); } @@ -83,8 +82,7 @@ struct distribute *distribute_lookup(struct distribute_ctx *ctx, dist = hash_lookup(ctx->disthash, &key); - if (key.ifname) - XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); + XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); return dist; } @@ -128,8 +126,7 @@ static struct distribute *distribute_get(struct distribute_ctx *ctx, ret = hash_get(ctx->disthash, &key, (void *(*)(void *))distribute_hash_alloc); - if (key.ifname) - XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); + XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); return ret; } @@ -163,8 +160,7 @@ static void distribute_list_set(struct distribute_ctx *ctx, dist = distribute_get(ctx, ifname); - if (dist->list[type]) - XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[type]); + XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[type]); dist->list[type] = XSTRDUP(MTYPE_DISTRIBUTE_NAME, alist_name); /* Apply this distribute-list to the interface. */ @@ -210,8 +206,7 @@ static void distribute_list_prefix_set(struct distribute_ctx *ctx, dist = distribute_get(ctx, ifname); - if (dist->prefix[type]) - XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[type]); + XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[type]); dist->prefix[type] = XSTRDUP(MTYPE_DISTRIBUTE_NAME, plist_name); /* Apply this distribute-list to the interface. */ diff --git a/lib/filter.c b/lib/filter.c index 317c1b68b..7df384f3b 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -242,11 +242,9 @@ static void access_list_delete(struct access_list *access) else list->head = access->next; - if (access->name) - XFREE(MTYPE_ACCESS_LIST_STR, access->name); + XFREE(MTYPE_ACCESS_LIST_STR, access->name); - if (access->remark) - XFREE(MTYPE_TMP, access->remark); + XFREE(MTYPE_TMP, access->remark); access_list_free(access); } diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index d7f655271..2a18e5cfc 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -110,8 +110,7 @@ void frr_pthread_destroy(struct frr_pthread *fpt) pthread_mutex_destroy(&fpt->mtx); pthread_mutex_destroy(fpt->running_cond_mtx); pthread_cond_destroy(fpt->running_cond); - if (fpt->name) - XFREE(MTYPE_FRR_PTHREAD, fpt->name); + XFREE(MTYPE_FRR_PTHREAD, fpt->name); XFREE(MTYPE_PTHREAD_PRIM, fpt->running_cond_mtx); XFREE(MTYPE_PTHREAD_PRIM, fpt->running_cond); XFREE(MTYPE_FRR_PTHREAD, fpt); diff --git a/lib/hash.c b/lib/hash.c index 611fd33fb..c02b81814 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -322,8 +322,7 @@ void hash_free(struct hash *hash) } pthread_mutex_unlock(&_hashes_mtx); - if (hash->name) - XFREE(MTYPE_HASH, hash->name); + XFREE(MTYPE_HASH, hash->name); XFREE(MTYPE_HASH_INDEX, hash->index); XFREE(MTYPE_HASH, hash); @@ -234,8 +234,7 @@ void if_delete(struct interface *ifp) if_link_params_free(ifp); - if (ifp->desc) - XFREE(MTYPE_TMP, ifp->desc); + XFREE(MTYPE_TMP, ifp->desc); XFREE(MTYPE_IF, ifp); } @@ -708,8 +707,7 @@ void connected_free(struct connected *connected) if (connected->destination) prefix_free(connected->destination); - if (connected->label) - XFREE(MTYPE_CONNECTED_LABEL, connected->label); + XFREE(MTYPE_CONNECTED_LABEL, connected->label); XFREE(MTYPE_CONNECTED, connected); } @@ -1349,8 +1347,7 @@ static int lib_interface_description_modify(enum nb_event event, return NB_OK; ifp = yang_dnode_get_entry(dnode, true); - if (ifp->desc) - XFREE(MTYPE_TMP, ifp->desc); + XFREE(MTYPE_TMP, ifp->desc); description = yang_dnode_get_string(dnode, NULL); ifp->desc = XSTRDUP(MTYPE_TMP, description); @@ -1366,8 +1363,7 @@ static int lib_interface_description_delete(enum nb_event event, return NB_OK; ifp = yang_dnode_get_entry(dnode, true); - if (ifp->desc) - XFREE(MTYPE_TMP, ifp->desc); + XFREE(MTYPE_TMP, ifp->desc); return NB_OK; } diff --git a/lib/if_rmap.c b/lib/if_rmap.c index 7ac536817..f8e500f43 100644 --- a/lib/if_rmap.c +++ b/lib/if_rmap.c @@ -46,13 +46,10 @@ static struct if_rmap *if_rmap_new(void) static void if_rmap_free(struct if_rmap *if_rmap) { - if (if_rmap->ifname) - XFREE(MTYPE_IF_RMAP_NAME, if_rmap->ifname); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->ifname); - if (if_rmap->routemap[IF_RMAP_IN]) - XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]); - if (if_rmap->routemap[IF_RMAP_OUT]) - XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]); XFREE(MTYPE_IF_RMAP, if_rmap); } @@ -67,8 +64,7 @@ struct if_rmap *if_rmap_lookup(const char *ifname) if_rmap = hash_lookup(ifrmaphash, &key); - if (key.ifname) - XFREE(MTYPE_IF_RMAP_NAME, key.ifname); + XFREE(MTYPE_IF_RMAP_NAME, key.ifname); return if_rmap; } @@ -104,8 +100,7 @@ static struct if_rmap *if_rmap_get(const char *ifname) ret = hash_get(ifrmaphash, &key, if_rmap_hash_alloc); - if (key.ifname) - XFREE(MTYPE_IF_RMAP_NAME, key.ifname); + XFREE(MTYPE_IF_RMAP_NAME, key.ifname); return ret; } @@ -133,16 +128,12 @@ static struct if_rmap *if_rmap_set(const char *ifname, enum if_rmap_type type, if_rmap = if_rmap_get(ifname); if (type == IF_RMAP_IN) { - if (if_rmap->routemap[IF_RMAP_IN]) - XFREE(MTYPE_IF_RMAP_NAME, - if_rmap->routemap[IF_RMAP_IN]); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]); if_rmap->routemap[IF_RMAP_IN] = XSTRDUP(MTYPE_IF_RMAP_NAME, routemap_name); } if (type == IF_RMAP_OUT) { - if (if_rmap->routemap[IF_RMAP_OUT]) - XFREE(MTYPE_IF_RMAP_NAME, - if_rmap->routemap[IF_RMAP_OUT]); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]); if_rmap->routemap[IF_RMAP_OUT] = XSTRDUP(MTYPE_IF_RMAP_NAME, routemap_name); } diff --git a/lib/keychain.c b/lib/keychain.c index 9aa3ef695..0a96c4cf0 100644 --- a/lib/keychain.c +++ b/lib/keychain.c @@ -116,8 +116,7 @@ static struct keychain *keychain_get(const char *name) static void keychain_delete(struct keychain *keychain) { - if (keychain->name) - XFREE(MTYPE_KEYCHAIN, keychain->name); + XFREE(MTYPE_KEYCHAIN, keychain->name); list_delete(&keychain->key); listnode_delete(keychain_list, keychain); @@ -217,8 +216,7 @@ static void key_delete(struct keychain *keychain, struct key *key) { listnode_delete(keychain->key, key); - if (key->string) - XFREE(MTYPE_KEY, key->string); + XFREE(MTYPE_KEY, key->string); key_free(key); } @@ -851,8 +851,7 @@ void closezlog(void) if (zl->fp != NULL) fclose(zl->fp); - if (zl->filename != NULL) - XFREE(MTYPE_ZLOG, zl->filename); + XFREE(MTYPE_ZLOG, zl->filename); XFREE(MTYPE_ZLOG, zl); zlog_default = NULL; @@ -911,8 +910,7 @@ int zlog_reset_file(void) logfile_fd = -1; zl->maxlvl[ZLOG_DEST_FILE] = ZLOG_DISABLED; - if (zl->filename) - XFREE(MTYPE_ZLOG, zl->filename); + XFREE(MTYPE_ZLOG, zl->filename); zl->filename = NULL; pthread_mutex_unlock(&loglock); diff --git a/lib/module.c b/lib/module.c index 6754b9457..098c55068 100644 --- a/lib/module.c +++ b/lib/module.c @@ -141,8 +141,7 @@ struct frrmod_runtime *frrmod_load(const char *spec, const char *dir, char *err, return rtinfo; out_fail: - if (rtinfo->load_args) - XFREE(MTYPE_MODULE_LOADARGS, rtinfo->load_args); + XFREE(MTYPE_MODULE_LOADARGS, rtinfo->load_args); XFREE(MTYPE_MODULE_LOADNAME, rtinfo->load_name); return NULL; } diff --git a/lib/netns_linux.c b/lib/netns_linux.c index ef2f5dc95..55c66fdc3 100644 --- a/lib/netns_linux.c +++ b/lib/netns_linux.c @@ -344,8 +344,7 @@ void ns_delete(struct ns *ns) // if_terminate (&ns->iflist); RB_REMOVE(ns_head, &ns_tree, ns); - if (ns->name) - XFREE(MTYPE_NS_NAME, ns->name); + XFREE(MTYPE_NS_NAME, ns->name); XFREE(MTYPE_NS, ns); } diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 23ea96f75..f940418d8 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -205,11 +205,9 @@ static int nhgl_cmp(struct nexthop_hold *nh1, struct nexthop_hold *nh2) static void nhgl_delete(struct nexthop_hold *nh) { - if (nh->intf) - XFREE(MTYPE_TMP, nh->intf); + XFREE(MTYPE_TMP, nh->intf); - if (nh->nhvrf_name) - XFREE(MTYPE_TMP, nh->nhvrf_name); + XFREE(MTYPE_TMP, nh->nhvrf_name); XFREE(MTYPE_TMP, nh); } diff --git a/lib/plist.c b/lib/plist.c index 41c8e4f8c..2a97e1e5b 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -326,8 +326,7 @@ static void prefix_list_delete(struct prefix_list *plist) else list->head = plist->next; - if (plist->desc) - XFREE(MTYPE_TMP, plist->desc); + XFREE(MTYPE_TMP, plist->desc); /* Make sure master's recent changed prefix-list information is cleared. */ @@ -338,8 +337,7 @@ static void prefix_list_delete(struct prefix_list *plist) if (master->delete_hook) (*master->delete_hook)(plist); - if (plist->name) - XFREE(MTYPE_MPREFIX_LIST_STR, plist->name); + XFREE(MTYPE_MPREFIX_LIST_STR, plist->name); XFREE(MTYPE_PREFIX_LIST_TRIE, plist->trie); diff --git a/lib/prefix.c b/lib/prefix.c index babd4304d..72ae0e635 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -944,8 +944,7 @@ int str2prefix_eth(const char *str, struct prefix_eth *p) ret = 1; done: - if (cp) - XFREE(MTYPE_TMP, cp); + XFREE(MTYPE_TMP, cp); return ret; } diff --git a/lib/routemap.c b/lib/routemap.c index 7c1ee2353..4898a8d0f 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -538,10 +538,8 @@ int generic_match_delete(struct vty *vty, struct route_map_index *index, break; } - if (dep_name) - XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); - if (rmap_name) - XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); + XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); + XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); return retval; } @@ -1075,8 +1073,7 @@ static void route_map_index_delete(struct route_map_index *index, int notify) index->map->head = index->next; /* Free 'char *nextrm' if not NULL */ - if (index->nextrm) - XFREE(MTYPE_ROUTE_MAP_NAME, index->nextrm); + XFREE(MTYPE_ROUTE_MAP_NAME, index->nextrm); /* Execute event hook. */ if (route_map_master.event_hook && notify) { @@ -1231,8 +1228,7 @@ static void route_map_rule_delete(struct route_map_rule_list *list, if (rule->cmd->func_free) (*rule->cmd->func_free)(rule->value); - if (rule->rule_str) - XFREE(MTYPE_ROUTE_MAP_RULE_STR, rule->rule_str); + XFREE(MTYPE_ROUTE_MAP_RULE_STR, rule->rule_str); if (rule->next) rule->next->prev = rule->prev; @@ -1779,8 +1775,7 @@ static int route_map_dep_update(struct hash *dephash, const char *dep_name, } ret_map_name = (char *)hash_release(dep->dep_rmap_hash, rname); - if (ret_map_name) - XFREE(MTYPE_ROUTE_MAP_NAME, ret_map_name); + XFREE(MTYPE_ROUTE_MAP_NAME, ret_map_name); if (!dep->dep_rmap_hash->count) { dep = hash_release(dephash, dname); diff --git a/lib/thread.c b/lib/thread.c index e757ff639..19ab40943 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -482,8 +482,7 @@ void thread_master_set_name(struct thread_master *master, const char *name) { pthread_mutex_lock(&master->mtx); { - if (master->name) - XFREE(MTYPE_THREAD_MASTER, master->name); + XFREE(MTYPE_THREAD_MASTER, master->name); master->name = XSTRDUP(MTYPE_THREAD_MASTER, name); } pthread_mutex_unlock(&master->mtx); @@ -647,8 +646,7 @@ void thread_master_free(struct thread_master *m) hash_free(m->cpu_record); m->cpu_record = NULL; - if (m->name) - XFREE(MTYPE_THREAD_MASTER, m->name); + XFREE(MTYPE_THREAD_MASTER, m->name); XFREE(MTYPE_THREAD_MASTER, m->handler.pfds); XFREE(MTYPE_THREAD_MASTER, m->handler.copy); XFREE(MTYPE_THREAD_MASTER, m); @@ -974,8 +974,7 @@ static void vty_complete_command(struct vty *vty) default: break; } - if (matched) - XFREE(MTYPE_TMP, matched); + XFREE(MTYPE_TMP, matched); } static void vty_describe_fold(struct vty *vty, int cmd_width, @@ -1169,8 +1168,7 @@ static void vty_hist_add(struct vty *vty) } /* Insert history entry. */ - if (vty->hist[vty->hindex]) - XFREE(MTYPE_VTY_HIST, vty->hist[vty->hindex]); + XFREE(MTYPE_VTY_HIST, vty->hist[vty->hindex]); vty->hist[vty->hindex] = XSTRDUP(MTYPE_VTY_HIST, vty->buf); /* History index rotation. */ @@ -2232,9 +2230,9 @@ void vty_close(struct vty *vty) buffer_free(vty->lbuf); /* Free command history. */ - for (i = 0; i < VTY_MAXHIST; i++) - if (vty->hist[i]) - XFREE(MTYPE_VTY_HIST, vty->hist[i]); + for (i = 0; i < VTY_MAXHIST; i++) { + XFREE(MTYPE_VTY_HIST, vty->hist[i]); + } /* Unset vector. */ if (vty->fd != -1) @@ -2255,8 +2253,7 @@ void vty_close(struct vty *vty) if (vty->fd == STDIN_FILENO) was_stdio = true; - if (vty->buf) - XFREE(MTYPE_VTY, vty->buf); + XFREE(MTYPE_VTY, vty->buf); if (vty->error) { vty->error->del = vty_error_delete; @@ -2546,8 +2543,7 @@ bool vty_read_config(struct nb_config *config, const char *config_file, host_config_set(fullpath); tmp_free_and_out: - if (tmp) - XFREE(MTYPE_TMP, tmp); + XFREE(MTYPE_TMP, tmp); return read_success; } @@ -3163,8 +3159,7 @@ void vty_init(struct thread_master *master_thread) void vty_terminate(void) { - if (vty_cwd) - XFREE(MTYPE_TMP, vty_cwd); + XFREE(MTYPE_TMP, vty_cwd); if (vtyvec && Vvty_serv_thread) { vty_reset(); |