Skip to content

Commit

Permalink
treewide: Cleanup free() calls.
Browse files Browse the repository at this point in the history
It's perfectly fine to call free(NULL).  Take advantage of that to
simplify the code.  Use the safer CONST_CAST way of "unconsting"
pointers we pass to free while we're at it.

Signed-off-by: Dumitru Ceara <dceara@redhat.com>
Acked-by: Ales Musil <amusil@redhat.com>
Signed-off-by: Mark Michelson <mmichels@redhat.com>
  • Loading branch information
dceara authored and putnopvut committed Jan 4, 2024
1 parent 5372ac4 commit 8b15ea3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 41 deletions.
12 changes: 3 additions & 9 deletions controller/ovn-controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,7 @@ add_pending_ct_zone_entry(struct shash *pending_ct_zones,
*/
struct ct_zone_pending_entry *existing =
shash_replace(pending_ct_zones, name, pending);
if (existing) {
free(existing);
}
free(existing);
}

static bool
Expand Down Expand Up @@ -6099,12 +6097,8 @@ main(int argc, char *argv[])

ovs_feature_support_destroy();
free(ovs_remote);
if (file_system_id) {
free(file_system_id);
}
if (cli_system_id) {
free(cli_system_id);
}
free(file_system_id);
free(cli_system_id);
ovn_exit_args_finish(&exit_args);
unixctl_server_destroy(unixctl);
service_stop();
Expand Down
5 changes: 1 addition & 4 deletions controller/pinctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,10 +1282,7 @@ fill_ipv6_prefix_state(struct ovsdb_idl_txn *ovnsb_idl_txn,
struct ipv6_prefixd_state *pfd;

if (!smap_get_bool(&pb->options, "ipv6_prefix", false)) {
pfd = shash_find_and_delete(&ipv6_prefixd, pb->logical_port);
if (pfd) {
free(pfd);
}
free(shash_find_and_delete(&ipv6_prefixd, pb->logical_port));
continue;
}

Expand Down
12 changes: 3 additions & 9 deletions controller/vif-plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,9 @@ destroy_port_ctx(struct vif_plug_port_ctx *ctx)
{
smap_destroy(&ctx->vif_plug_port_ctx_in.lport_options);
smap_destroy(&ctx->vif_plug_port_ctx_in.iface_options);
if (ctx->vif_plug_port_ctx_in.lport_name) {
free((char *)ctx->vif_plug_port_ctx_in.lport_name);
}
if (ctx->vif_plug_port_ctx_in.iface_name) {
free((char *)ctx->vif_plug_port_ctx_in.iface_name);
}
if (ctx->vif_plug_port_ctx_in.iface_type) {
free((char *)ctx->vif_plug_port_ctx_in.iface_type);
}
free(CONST_CAST(char *, ctx->vif_plug_port_ctx_in.lport_name));
free(CONST_CAST(char *, ctx->vif_plug_port_ctx_in.iface_name));
free(CONST_CAST(char *, ctx->vif_plug_port_ctx_in.iface_type));
/* Note that data associated with ctx->vif_plug_port_ctx_out must be
* destroyed by the plug provider implementation with a call to
* vif_plug_port_ctx_destroy prior to calling this function */
Expand Down
22 changes: 8 additions & 14 deletions lib/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,13 @@ expr_combine(enum expr_type type, struct expr *a, struct expr *b)
} else {
ovs_list_push_back(&a->andor, &b->node);
}
if (a->as_name) {
free(a->as_name);
a->as_name = NULL;
}
free(a->as_name);
a->as_name = NULL;
return a;
} else if (b->type == type) {
ovs_list_push_front(&b->andor, &a->node);
if (b->as_name) {
free(b->as_name);
b->as_name = NULL;
}
free(b->as_name);
b->as_name = NULL;
return b;
} else {
struct expr *e = expr_create_andor(type);
Expand Down Expand Up @@ -879,12 +875,10 @@ parse_constant(struct expr_context *ctx, struct expr_constant_set *cs,
sizeof *cs->values);
}

if (cs->as_name) {
/* Combining other values to the constant set that is tracking an
* address set, so untrack it. */
free(cs->as_name);
cs->as_name = NULL;
}
/* Combining other values to the constant set that is tracking an
* address set, so untrack it. */
free(cs->as_name);
cs->as_name = NULL;

if (ctx->lexer->token.type == LEX_T_TEMPLATE) {
lexer_error(ctx->lexer, "Unexpanded template.");
Expand Down
6 changes: 2 additions & 4 deletions lib/ovn-parallel-hmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,8 @@ ovn_update_hashrow_locks(struct hmap *lflows, struct hashrow_locks *hrl)
{
int i;
if (hrl->mask != lflows->mask) {
if (hrl->row_locks) {
free(hrl->row_locks);
}
hrl->row_locks = xcalloc(sizeof(struct ovs_mutex), lflows->mask + 1);
hrl->row_locks = xrealloc(hrl->row_locks,
sizeof *hrl->row_locks * (lflows->mask + 1));
hrl->mask = lflows->mask;
for (i = 0; i <= lflows->mask; i++) {
ovs_mutex_init(&hrl->row_locks[i]);
Expand Down
2 changes: 1 addition & 1 deletion northd/ipam.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void
destroy_ipam_info(struct ipam_info *info)
{
bitmap_free(info->allocated_ipv4s);
free((char *) info->id);
free(CONST_CAST(char *, info->id));
}

bool
Expand Down

0 comments on commit 8b15ea3

Please sign in to comment.