summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2019-03-06 15:54:44 +0100
committerGitHub <noreply@github.com>2019-03-06 15:54:44 +0100
commitd3b05897edff14ceb71c2f5603a9fcdb1ae10c83 (patch)
tree274b088939d9686c289d5de95d70cdb39a01e4b4 /lib
parentRevert "nhrpd: strncpy -> strlcpy" (diff)
parenttools: add coccinelle spatches (diff)
downloadfrr-d3b05897edff14ceb71c2f5603a9fcdb1ae10c83.tar.xz
frr-d3b05897edff14ceb71c2f5603a9fcdb1ae10c83.zip
Merge pull request #3869 from qlyoung/cocci-fixes
Assorted Coccinelle fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/command.c45
-rw-r--r--lib/command_graph.c2
-rw-r--r--lib/distribute.c27
-rw-r--r--lib/filter.c12
-rw-r--r--lib/frr_pthread.c3
-rw-r--r--lib/frr_zmq.c4
-rw-r--r--lib/frrstr.c4
-rw-r--r--lib/hash.c5
-rw-r--r--lib/if.c12
-rw-r--r--lib/if_rmap.c23
-rw-r--r--lib/imsg.c3
-rw-r--r--lib/jhash.c4
-rw-r--r--lib/keychain.c6
-rw-r--r--lib/libfrr.c2
-rw-r--r--lib/log.c6
-rw-r--r--lib/module.c3
-rw-r--r--lib/netns_linux.c3
-rw-r--r--lib/nexthop_group.c6
-rw-r--r--lib/northbound_confd.c2
-rw-r--r--lib/plist.c6
-rw-r--r--lib/pqueue.c2
-rw-r--r--lib/prefix.c9
-rw-r--r--lib/routemap.c15
-rw-r--r--lib/thread.c8
-rw-r--r--lib/vty.c21
-rw-r--r--lib/workqueue.c2
-rw-r--r--lib/yang_wrappers.c2
27 files changed, 82 insertions, 155 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/command_graph.c b/lib/command_graph.c
index 0e8669c4b..4757fd951 100644
--- a/lib/command_graph.c
+++ b/lib/command_graph.c
@@ -471,7 +471,7 @@ void cmd_graph_node_print_cb(struct graph_node *gn, struct buffer *buf)
struct cmd_token *tok = gn->data;
const char *color;
- if (wasend == true) {
+ if (wasend) {
wasend = false;
return;
}
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..276df4b4d 100644
--- a/lib/filter.c
+++ b/lib/filter.c
@@ -128,8 +128,7 @@ static struct access_master *access_master_get(afi_t afi)
/* Allocate new filter structure. */
static struct filter *filter_new(void)
{
- return (struct filter *)XCALLOC(MTYPE_ACCESS_FILTER,
- sizeof(struct filter));
+ return XCALLOC(MTYPE_ACCESS_FILTER, sizeof(struct filter));
}
static void filter_free(struct filter *filter)
@@ -202,8 +201,7 @@ static int filter_match_zebra(struct filter *mfilter, const struct prefix *p)
/* Allocate new access list structure. */
static struct access_list *access_list_new(void)
{
- return (struct access_list *)XCALLOC(MTYPE_ACCESS_LIST,
- sizeof(struct access_list));
+ return XCALLOC(MTYPE_ACCESS_LIST, sizeof(struct access_list));
}
/* Free allocated access_list. */
@@ -242,11 +240,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/frr_zmq.c b/lib/frr_zmq.c
index cfea238d9..7781beae5 100644
--- a/lib/frr_zmq.c
+++ b/lib/frr_zmq.c
@@ -176,8 +176,6 @@ int funcname_frrzmq_thread_add_read(struct thread_master *master,
cb = *cbp;
else {
cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb));
- if (!cb)
- return -1;
cb->write.cancelled = 1;
*cbp = cb;
@@ -286,8 +284,6 @@ int funcname_frrzmq_thread_add_write(struct thread_master *master,
cb = *cbp;
else {
cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb));
- if (!cb)
- return -1;
cb->read.cancelled = 1;
*cbp = cb;
diff --git a/lib/frrstr.c b/lib/frrstr.c
index 85d968182..fd337073f 100644
--- a/lib/frrstr.c
+++ b/lib/frrstr.c
@@ -155,13 +155,13 @@ void frrstr_strvec_free(vector v)
bool begins_with(const char *str, const char *prefix)
{
if (!str || !prefix)
- return 0;
+ return false;
size_t lenstr = strlen(str);
size_t lenprefix = strlen(prefix);
if (lenprefix > lenstr)
- return 0;
+ return false;
return strncmp(str, prefix, lenprefix) == 0;
}
diff --git a/lib/hash.c b/lib/hash.c
index 9f9fc31d3..c02b81814 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -95,8 +95,6 @@ static void hash_expand(struct hash *hash)
new_index = XCALLOC(MTYPE_HASH_INDEX,
sizeof(struct hash_bucket *) * new_size);
- if (new_index == NULL)
- return;
hash->stats.empty = new_size;
@@ -324,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);
diff --git a/lib/if.c b/lib/if.c
index 48841c7ee..abcc6c5d3 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -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 53bbcbfe5..955c1417c 100644
--- a/lib/if_rmap.c
+++ b/lib/if_rmap.c
@@ -44,13 +44,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);
}
@@ -65,8 +62,7 @@ struct if_rmap *if_rmap_lookup(struct if_rmap_ctx *ctx, const char *ifname)
if_rmap = hash_lookup(ctx->ifrmaphash, &key);
- if (key.ifname)
- XFREE(MTYPE_IF_RMAP_NAME, key.ifname);
+ XFREE(MTYPE_IF_RMAP_NAME, key.ifname);
return if_rmap;
}
@@ -106,8 +102,7 @@ static struct if_rmap *if_rmap_get(struct if_rmap_ctx *ctx, const char *ifname)
ret = hash_get(ctx->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;
}
@@ -136,16 +131,12 @@ static struct if_rmap *if_rmap_set(struct if_rmap_ctx *ctx,
if_rmap = if_rmap_get(ctx, 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/imsg.c b/lib/imsg.c
index 935d13772..57e70617d 100644
--- a/lib/imsg.c
+++ b/lib/imsg.c
@@ -18,6 +18,7 @@
#include <zebra.h>
+#include "memory.h"
#include "queue.h"
#include "imsg.h"
@@ -35,7 +36,7 @@ static int available_fds(unsigned int n)
unsigned int i;
int ret, fds[256];
- if (n > (sizeof(fds) / sizeof(fds[0])))
+ if (n > (unsigned int)array_size(fds))
return (1);
ret = 0;
diff --git a/lib/jhash.c b/lib/jhash.c
index cb6946f37..0d561ef3a 100644
--- a/lib/jhash.c
+++ b/lib/jhash.c
@@ -116,7 +116,7 @@ uint32_t jhash(const void *key, uint32_t length, uint32_t initval)
/* fallthru */
case 1:
a += k[0];
- };
+ }
__jhash_mix(a, b, c);
@@ -151,7 +151,7 @@ uint32_t jhash2(const uint32_t *k, uint32_t length, uint32_t initval)
/* fallthru */
case 1:
a += k[0];
- };
+ }
__jhash_mix(a, b, c);
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);
}
diff --git a/lib/libfrr.c b/lib/libfrr.c
index 9119b0499..1afe30d61 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -61,7 +61,7 @@ static char dbfile_default[512];
#endif
static char vtypath_default[256];
-bool debug_memstats_at_exit = 0;
+bool debug_memstats_at_exit = false;
static bool nodetach_term, nodetach_daemon;
static char comb_optstr[256];
diff --git a/lib/log.c b/lib/log.c
index c424a5bc9..e98040eb0 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -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/northbound_confd.c b/lib/northbound_confd.c
index a8e001781..a499d48c1 100644
--- a/lib/northbound_confd.c
+++ b/lib/northbound_confd.c
@@ -1383,7 +1383,7 @@ error:
static int frr_confd_finish(void)
{
- if (confd_connected == false)
+ if (!confd_connected)
return 0;
frr_confd_finish_cdb();
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/pqueue.c b/lib/pqueue.c
index 1565de216..87b54a681 100644
--- a/lib/pqueue.c
+++ b/lib/pqueue.c
@@ -133,8 +133,6 @@ static int pqueue_expand(struct pqueue *queue)
newarray =
XCALLOC(MTYPE_PQUEUE_DATA, queue->array_size * DATA_SIZE * 2);
- if (newarray == NULL)
- return 0;
memcpy(newarray, queue->array, queue->array_size * DATA_SIZE);
diff --git a/lib/prefix.c b/lib/prefix.c
index 80a89cc3c..52bb266f1 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;
}
@@ -1503,8 +1502,7 @@ char *prefix_mac2str(const struct ethaddr *mac, char *buf, int size)
if (!mac)
return NULL;
if (!buf)
- ptr = (char *)XMALLOC(MTYPE_TMP,
- ETHER_ADDR_STRLEN * sizeof(char));
+ ptr = XMALLOC(MTYPE_TMP, ETHER_ADDR_STRLEN * sizeof(char));
else {
assert(size >= ETHER_ADDR_STRLEN);
ptr = buf;
@@ -1585,8 +1583,7 @@ char *esi_to_str(const esi_t *esi, char *buf, int size)
if (!esi)
return NULL;
if (!buf)
- ptr = (char *)XMALLOC(MTYPE_TMP,
- ESI_STR_LEN * sizeof(char));
+ ptr = XMALLOC(MTYPE_TMP, ESI_STR_LEN * sizeof(char));
else {
assert(size >= ESI_STR_LEN);
ptr = buf;
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 055587434..19ab40943 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -414,8 +414,6 @@ struct thread_master *thread_master_create(const char *name)
pthread_once(&init_once, &initializer);
rv = XCALLOC(MTYPE_THREAD_MASTER, sizeof(struct thread_master));
- if (rv == NULL)
- return NULL;
/* Initialize master mutex */
pthread_mutex_init(&rv->mtx, NULL);
@@ -484,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);
@@ -649,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);
diff --git a/lib/vty.c b/lib/vty.c
index d6fda8cbb..0bcee6a80 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -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();
diff --git a/lib/workqueue.c b/lib/workqueue.c
index fa69ec600..066d81f35 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -274,7 +274,7 @@ int work_queue_run(struct thread *thread)
wq->cycles.granularity = WORK_QUEUE_MIN_GRANULARITY;
STAILQ_FOREACH_SAFE (item, &wq->items, wq, titem) {
- assert(item && item->data);
+ assert(item->data);
/* dont run items which are past their allowed retries */
if (item->ran > wq->spec.max_retries) {
diff --git a/lib/yang_wrappers.c b/lib/yang_wrappers.c
index 6273dff3c..7ecea5f44 100644
--- a/lib/yang_wrappers.c
+++ b/lib/yang_wrappers.c
@@ -62,7 +62,7 @@ bool yang_str2bool(const char *value)
struct yang_data *yang_data_new_bool(const char *xpath, bool value)
{
- return yang_data_new(xpath, (value == true) ? "true" : "false");
+ return yang_data_new(xpath, (value) ? "true" : "false");
}
bool yang_dnode_get_bool(const struct lyd_node *dnode, const char *xpath_fmt,