diff --git a/ai/default/daisettler.c b/ai/default/daisettler.c index 33517a1e7f..c523812d17 100644 --- a/ai/default/daisettler.c +++ b/ai/default/daisettler.c @@ -492,9 +492,7 @@ struct tile_data_cache * *****************************************************************************/ static void tile_data_cache_destroy(struct tile_data_cache *ptdc) { - if (ptdc) { - free(ptdc); - } + free(ptdc); } /*************************************************************************//** diff --git a/client/control.c b/client/control.c index 06aa3fc7f5..44753efcf7 100644 --- a/client/control.c +++ b/client/control.c @@ -1746,9 +1746,7 @@ void action_confirmation(struct act_confirmation_data *data, bool confirm) } } - if (data->name != NULL) { - free(data->name); - } + free(data->name); free(data); } diff --git a/client/gui-gtk-3.22/editprop.c b/client/gui-gtk-3.22/editprop.c index 75fd39639f..f0108c64e4 100644 --- a/client/gui-gtk-3.22/editprop.c +++ b/client/gui-gtk-3.22/editprop.c @@ -1862,9 +1862,7 @@ static struct propval *objbind_get_value_from_object(struct objbind *ob, __FUNCTION__, objtype_get_name(objtype), objtype); FAILED: - if (NULL != pv) { - free(pv); - } + free(pv); return NULL; } diff --git a/client/gui-gtk-3.22/gui_stuff.c b/client/gui-gtk-3.22/gui_stuff.c index 3abfb4c940..7447952a7f 100644 --- a/client/gui-gtk-3.22/gui_stuff.c +++ b/client/gui-gtk-3.22/gui_stuff.c @@ -359,9 +359,7 @@ static void gui_dialog_destroy_handler(GtkWidget *w, struct gui_dialog *dlg) } } - if (dlg->title) { - free(dlg->title); - } + free(dlg->title); free(dlg); } @@ -934,9 +932,7 @@ void gui_dialog_set_default_size(struct gui_dialog *dlg, int width, int height) **************************************************************************/ void gui_dialog_set_title(struct gui_dialog *dlg, const char *title) { - if (dlg->title) { - free(dlg->title); - } + free(dlg->title); dlg->title = fc_strdup(title); switch (dlg->type) { case GUI_DIALOG_WINDOW: diff --git a/client/gui-gtk-4.0/editprop.c b/client/gui-gtk-4.0/editprop.c index 1c457906a7..72e592beee 100644 --- a/client/gui-gtk-4.0/editprop.c +++ b/client/gui-gtk-4.0/editprop.c @@ -1862,9 +1862,7 @@ static struct propval *objbind_get_value_from_object(struct objbind *ob, __FUNCTION__, objtype_get_name(objtype), objtype); FAILED: - if (NULL != pv) { - free(pv); - } + free(pv); return NULL; } diff --git a/client/gui-gtk-4.0/gui_stuff.c b/client/gui-gtk-4.0/gui_stuff.c index 9025fb2986..9734f3ef71 100644 --- a/client/gui-gtk-4.0/gui_stuff.c +++ b/client/gui-gtk-4.0/gui_stuff.c @@ -335,9 +335,7 @@ static void gui_dialog_destroy_handler(GtkWidget *w, struct gui_dialog *dlg) } } - if (dlg->title) { - free(dlg->title); - } + free(dlg->title); free(dlg); } @@ -872,9 +870,7 @@ void gui_dialog_set_default_size(struct gui_dialog *dlg, int width, int height) **************************************************************************/ void gui_dialog_set_title(struct gui_dialog *dlg, const char *title) { - if (dlg->title) { - free(dlg->title); - } + free(dlg->title); dlg->title = fc_strdup(title); switch (dlg->type) { case GUI_DIALOG_WINDOW: diff --git a/client/gui-sdl2/colors.c b/client/gui-sdl2/colors.c index 9740e8b0e0..06fcf7655f 100644 --- a/client/gui-sdl2/colors.c +++ b/client/gui-sdl2/colors.c @@ -103,9 +103,7 @@ void color_free(struct color *pcolor) return; } - if (pcolor->color) { - free(pcolor->color); - } + free(pcolor->color); free(pcolor); } diff --git a/client/packhand.c b/client/packhand.c index f4e02fa130..bc72ed0ee8 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -1811,9 +1811,7 @@ static bool handle_unit_packet_common(struct unit *packet_unit) punit->orders.vigilant = packet_unit->orders.vigilant; /* We cheat by just stealing the packet unit's list. */ - if (punit->orders.list) { - free(punit->orders.list); - } + free(punit->orders.list); punit->orders.list = packet_unit->orders.list; packet_unit->orders.list = NULL; @@ -3255,9 +3253,7 @@ void handle_tile_info(const struct packet_tile_info *packet) if (packet->spec_sprite[0] != '\0') { if (!ptile->spec_sprite || strcmp(ptile->spec_sprite, packet->spec_sprite) != 0) { - if (ptile->spec_sprite) { - free(ptile->spec_sprite); - } + free(ptile->spec_sprite); ptile->spec_sprite = fc_strdup(packet->spec_sprite); tile_changed = TRUE; } @@ -3468,9 +3464,7 @@ void handle_ruleset_summary(const struct packet_ruleset_summary *packet) { int len; - if (game.ruleset_summary != NULL) { - free(game.ruleset_summary); - } + free(game.ruleset_summary); len = strlen(packet->text); @@ -4009,14 +4003,10 @@ void handle_ruleset_terrain(const struct packet_ruleset_terrain *p) pterrain->output[o] = p->output[o]; } output_type_iterate_end; - if (pterrain->resources != NULL) { - free(pterrain->resources); - } + free(pterrain->resources); pterrain->resources = fc_calloc(p->num_resources + 1, sizeof(*pterrain->resources)); - if (pterrain->resource_freq != NULL) { - free(pterrain->resource_freq); - } + free(pterrain->resource_freq); pterrain->resource_freq = fc_calloc(p->num_resources + 1, sizeof(*pterrain->resource_freq)); for (j = 0; j < p->num_resources; j++) { diff --git a/client/reqtree.c b/client/reqtree.c index 5abfc009e9..48939eba6b 100644 --- a/client/reqtree.c +++ b/client/reqtree.c @@ -484,9 +484,7 @@ void destroy_reqtree(struct reqtree *tree) for (i = 0; i < tree->num_layers; i++) { free(tree->layers[i]); } - if (tree->layer_size) { - free(tree->layer_size); - } + free(tree->layer_size); } free(tree); } diff --git a/client/tilespec.c b/client/tilespec.c index e7064befdb..4a54388b1f 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -662,9 +662,7 @@ static void drawing_data_destroy(struct drawing_data *draw) fc_assert_ret(NULL != draw); - if (draw->name != NULL) { - free(draw->name); - } + free(draw->name); for (i = 0; i < 4; i++) { if (draw->blend[i]) { free_sprite(draw->blend[i]); @@ -3118,9 +3116,7 @@ static void free_city_sprite(struct city_sprite *city_sprite) return; } for (style = 0; style < city_sprite->num_styles; style++) { - if (city_sprite->styles[style].land_thresholds) { - free(city_sprite->styles[style].land_thresholds); - } + free(city_sprite->styles[style].land_thresholds); } free(city_sprite->styles); free(city_sprite); @@ -6581,9 +6577,7 @@ void tileset_free_tiles(struct tileset *t) small_sprite_list_iterate(t->small_sprites, ss) { small_sprite_list_remove(t->small_sprites, ss); - if (ss->file) { - free(ss->file); - } + free(ss->file); fc_assert(ss->sprite == NULL); free(ss); } small_sprite_list_iterate_end; @@ -7441,9 +7435,7 @@ void tileset_ruleset_reset(struct tileset *t) t->flagged_bases_list = extra_type_list_new(); } - if (t->sprites.style_citizen_sets.sets != NULL) { - free(t->sprites.style_citizen_sets.sets); - } + free(t->sprites.style_citizen_sets.sets); t->sprites.style_citizen_sets.sets = fc_malloc(game.control.num_city_styles diff --git a/client/voteinfo.c b/client/voteinfo.c index 77a3694b09..8ac6d66d5e 100644 --- a/client/voteinfo.c +++ b/client/voteinfo.c @@ -183,9 +183,7 @@ void voteinfo_queue_free(void) } voteinfo_list_iterate(voteinfo_queue, vi) { - if (vi != NULL) { - free(vi); - } + free(vi); } voteinfo_list_iterate_end; voteinfo_list_destroy(voteinfo_queue); diff --git a/common/aicore/path_finding.c b/common/aicore/path_finding.c index 1dd6c04813..5e46d222db 100644 --- a/common/aicore/path_finding.c +++ b/common/aicore/path_finding.c @@ -1853,9 +1853,7 @@ static void pf_danger_map_destroy(struct pf_map *pfm) /* Need to clean up the dangling danger segments. */ for (i = 0, node = pfdm->lattice; i < MAP_INDEX_SIZE; i++, node++) { - if (node->danger_segment) { - free(node->danger_segment); - } + free(node->danger_segment); } free(pfdm->lattice); map_index_pq_destroy(pfdm->queue); diff --git a/common/city.c b/common/city.c index 0de4bd8476..699856159d 100644 --- a/common/city.c +++ b/common/city.c @@ -1128,9 +1128,7 @@ const char *city_name_get(const struct city *pcity) **************************************************************************/ void city_name_set(struct city *pcity, const char *new_name) { - if (pcity->name != NULL) { - free(pcity->name); - } + free(pcity->name); if (strlen(new_name) < MAX_LEN_CITYNAME) { pcity->name = fc_strdup(new_name); @@ -3430,17 +3428,11 @@ void destroy_city_virtual(struct city *pcity) unit_list_destroy(pcity->units_supported); trade_route_list_destroy(pcity->routes); - if (pcity->tile_cache != NULL) { - free(pcity->tile_cache); - } + free(pcity->tile_cache); - if (pcity->cm_parameter) { - free(pcity->cm_parameter); - } + free(pcity->cm_parameter); - if (pcity->counter_values) { - free(pcity->counter_values); - } + free(pcity->counter_values); if (!is_server()) { unit_list_destroy(pcity->client.info_units_supported); diff --git a/common/effects.c b/common/effects.c index 502a3a5f91..5e3af568ea 100644 --- a/common/effects.c +++ b/common/effects.c @@ -216,9 +216,7 @@ struct effect *effect_new(enum effect_type type, int value, void effect_free(struct effect *peffect) { requirement_vector_free(&peffect->reqs); - if (peffect->rulesave.comment != NULL) { - free(peffect->rulesave.comment); - } + free(peffect->rulesave.comment); free(peffect); } diff --git a/common/networking/connection.c b/common/networking/connection.c index 7fe12c8390..3b3840316f 100644 --- a/common/networking/connection.c +++ b/common/networking/connection.c @@ -455,9 +455,7 @@ struct socket_packet_buffer *new_socket_packet_buffer(void) static void free_socket_packet_buffer(struct socket_packet_buffer *buf) { if (buf) { - if (buf->data) { - free(buf->data); - } + free(buf->data); free(buf); } } @@ -635,9 +633,7 @@ void connection_common_close(struct connection *pconn) fc_closesocket(pconn->sock); pconn->used = FALSE; pconn->established = FALSE; - if (NULL != pconn->closing_reason) { - free(pconn->closing_reason); - } + free(pconn->closing_reason); free_socket_packet_buffer(pconn->buffer); pconn->buffer = NULL; diff --git a/common/networking/packets.c b/common/networking/packets.c index 02abf396d2..0c96a9e7f5 100644 --- a/common/networking/packets.c +++ b/common/networking/packets.c @@ -729,9 +729,7 @@ void generic_handle_player_attribute_chunk(struct player *pplayer, if (chunk->offset + chunk->chunk_length == chunk->total_length) { /* Received full attribute block */ - if (pplayer->attribute_block.data != NULL) { - free(pplayer->attribute_block.data); - } + free(pplayer->attribute_block.data); pplayer->attribute_block.data = pplayer->attribute_block_buffer.data; pplayer->attribute_block.length = pplayer->attribute_block_buffer.length; diff --git a/common/scriptcore/luascript_signal.c b/common/scriptcore/luascript_signal.c index 6973e17299..c934203f59 100644 --- a/common/scriptcore/luascript_signal.c +++ b/common/scriptcore/luascript_signal.c @@ -150,15 +150,9 @@ static struct signal *signal_new(int nargs, enum api_types *parg_types) **************************************************************************/ static void signal_destroy(struct signal *psignal) { - if (psignal->arg_types) { - free(psignal->arg_types); - } - if (psignal->deprecator.depr_msg) { - free(psignal->deprecator.depr_msg); - } - if (psignal->deprecator.retired) { - free(psignal->deprecator.retired); - } + free(psignal->arg_types); + free(psignal->deprecator.depr_msg); + free(psignal->deprecator.retired); signal_callback_list_destroy(psignal->callbacks); free(psignal); } diff --git a/common/team.c b/common/team.c index 52a9df5f5f..2d5289b5d7 100644 --- a/common/team.c +++ b/common/team.c @@ -88,16 +88,10 @@ void team_slots_free(void) if (NULL != tslot->team) { team_destroy(tslot->team); } - if (NULL != tslot->defined_name) { - free(tslot->defined_name); - } - if (NULL != tslot->rule_name) { - free(tslot->rule_name); - } + free(tslot->defined_name); + free(tslot->rule_name); #ifdef FREECIV_ENABLE_NLS - if (NULL != tslot->name_translation) { - free(tslot->name_translation); - } + free(tslot->name_translation); #endif /* FREECIV_ENABLE_NLS */ } team_slots_iterate_end; free(team_slots.slots); @@ -292,20 +286,14 @@ void team_slot_set_defined_name(struct team_slot *tslot, fc_assert_ret(NULL != tslot); fc_assert_ret(NULL != team_name); - if (NULL != tslot->defined_name) { - free(tslot->defined_name); - } + free(tslot->defined_name); tslot->defined_name = fc_strdup(team_name); - if (NULL != tslot->rule_name) { - free(tslot->rule_name); - } + free(tslot->rule_name); tslot->rule_name = fc_strdup(Qn_(team_name)); #ifdef FREECIV_ENABLE_NLS - if (NULL != tslot->name_translation) { - free(tslot->name_translation); - } + free(tslot->name_translation); tslot->name_translation = fc_strdup(Q_(team_name)); #endif /* FREECIV_ENABLE_NLS */ } diff --git a/common/unittype.c b/common/unittype.c index e3a96320b0..4fd9cdb7ba 100644 --- a/common/unittype.c +++ b/common/unittype.c @@ -2730,9 +2730,7 @@ struct veteran_system *veteran_system_new(int count) void veteran_system_destroy(struct veteran_system *vsystem) { if (vsystem) { - if (vsystem->definitions) { - free(vsystem->definitions); - } + free(vsystem->definitions); free(vsystem); } } diff --git a/common/vision.c b/common/vision.c index b6e5838d56..50b3bffeaf 100644 --- a/common/vision.c +++ b/common/vision.c @@ -73,9 +73,7 @@ bool vision_reveal_tiles(struct vision *vision, bool reveal_tiles) ****************************************************************************/ void vision_site_destroy(struct vision_site *psite) { - if (psite->name != NULL) { - free(psite->name); - } + free(psite->name); free(psite); } @@ -123,9 +121,7 @@ void vision_site_update_from_city(struct vision_site *psite, vision_site_size_set(psite, city_size_get(pcity)); - if (psite->name != NULL) { - free(psite->name); - } + free(psite->name); psite->name = fc_strdup(city_name_get(pcity)); } diff --git a/server/advisors/advchoice.c b/server/advisors/advchoice.c index 918081af06..d6f95fdf42 100644 --- a/server/advisors/advchoice.c +++ b/server/advisors/advchoice.c @@ -71,9 +71,7 @@ struct adv_choice *adv_new_choice(void) void adv_free_choice(struct adv_choice *choice) { #ifdef ADV_CHOICE_TRACK - if (choice->use != NULL) { - free(choice->use); - } + free(choice->use); #endif /* ADV_CHOICE_TRACK */ free(choice); } @@ -128,9 +126,7 @@ void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src) dest->value = src->value; dest->want = src->want; dest->need_boat = src->need_boat; - if (dest->use != NULL) { - free(dest->use); - } + free(dest->use); if (src->use != NULL) { dest->use = fc_strdup(src->use); } else { @@ -145,9 +141,7 @@ void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src) **************************************************************************/ void adv_choice_set_use(struct adv_choice *choice, const char *use) { - if (choice->use != NULL) { - free(choice->use); - } + free(choice->use); choice->use = fc_strdup(use); } diff --git a/server/advisors/advdata.c b/server/advisors/advdata.c index c3a7f00f23..446f1a4981 100644 --- a/server/advisors/advdata.c +++ b/server/advisors/advdata.c @@ -757,9 +757,7 @@ void adv_data_close(struct player *pplayer) adv_data_phase_done(pplayer); - if (adv->government_want != NULL) { - free(adv->government_want); - } + free(adv->government_want); if (adv->dipl.adv_dipl_slots != NULL) { players_iterate(aplayer) { @@ -771,9 +769,7 @@ void adv_data_close(struct player *pplayer) FC_FREE(adv->dipl.adv_dipl_slots); } - if (adv != NULL) { - free(adv); - } + free(adv); pplayer->server.adv = NULL; } diff --git a/server/edithand.c b/server/edithand.c index e7a87cdf6c..f2a3b139ed 100644 --- a/server/edithand.c +++ b/server/edithand.c @@ -84,9 +84,7 @@ void edithand_init(void) need_continents_reassigned = FALSE; - if (unfogged_players != NULL) { - free(unfogged_players); - } + free(unfogged_players); unfogged_players = fc_calloc(player_slot_count(), sizeof(bool)); } diff --git a/server/notify.c b/server/notify.c index cd372613d9..709d7fe030 100644 --- a/server/notify.c +++ b/server/notify.c @@ -680,9 +680,7 @@ void event_cache_add_for_players(const struct packet_chat_msg *packet, server_state(), ECT_PLAYERS, players); } - if (NULL != players) { - free(players); - } + free(players); } /**********************************************************************//** diff --git a/server/report.c b/server/report.c index 17837df049..fa9bd2a2db 100644 --- a/server/report.c +++ b/server/report.c @@ -1447,9 +1447,7 @@ void log_civ_score_free(void) player_slots_iterate(pslot) { struct plrdata_slot *plrdata = score_log->plrdata + player_slot_index(pslot); - if (plrdata->name != NULL) { - free(plrdata->name); - } + free(plrdata->name); } player_slots_iterate_end; free(score_log->plrdata); } diff --git a/server/ruleset.c b/server/ruleset.c index 80df66b92e..017043d92b 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -894,9 +894,7 @@ static bool lookup_unit_list(struct section_file *file, const char *prefix, slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry); if (nval == 0) { /* 'No vector' is considered same as empty vector */ - if (slist != NULL) { - free(slist); - } + free(slist); return TRUE; } if (nval > MAX_NUM_UNIT_LIST) { @@ -2044,21 +2042,11 @@ static bool load_ruleset_veteran(struct section_file *file, #undef rs_sanity_veteran } - if (vlist_name) { - free(vlist_name); - } - if (vlist_power) { - free(vlist_power); - } - if (vlist_raise) { - free(vlist_raise); - } - if (vlist_wraise) { - free(vlist_wraise); - } - if (vlist_move) { - free(vlist_move); - } + free(vlist_name); + free(vlist_power); + free(vlist_raise); + free(vlist_wraise); + free(vlist_move); return ret; } @@ -2848,9 +2836,7 @@ static bool load_terrain_names(struct section_file *file, game.control.terrain_count = nval; /* avoid re-reading files */ - if (terrain_sections) { - free(terrain_sections); - } + free(terrain_sections); terrain_sections = fc_calloc(nval, MAX_SECTION_LABEL); terrain_type_iterate(pterrain) { @@ -2887,9 +2873,7 @@ static bool load_terrain_names(struct section_file *file, game.control.num_extra_types = nval; - if (extra_sections) { - free(extra_sections); - } + free(extra_sections); extra_sections = fc_calloc(nval, MAX_SECTION_LABEL); if (ok) { @@ -2927,9 +2911,7 @@ static bool load_terrain_names(struct section_file *file, if (ok) { int idx; - if (base_sections) { - free(base_sections); - } + free(base_sections); base_sections = fc_calloc(nval, MAX_SECTION_LABEL); /* Cannot use base_type_iterate() before bases are added to @@ -2980,9 +2962,7 @@ static bool load_terrain_names(struct section_file *file, if (ok) { int idx; - if (road_sections) { - free(road_sections); - } + free(road_sections); road_sections = fc_calloc(nval, MAX_SECTION_LABEL); /* Cannot use extra_type_by_cause_iterate(EC_ROAD) before roads are added to @@ -3033,9 +3013,7 @@ static bool load_terrain_names(struct section_file *file, if (ok) { int idx; - if (resource_sections) { - free(resource_sections); - } + free(resource_sections); resource_sections = fc_calloc(nval, MAX_SECTION_LABEL); /* Cannot use resource_type_iterate() before resource are added to @@ -4859,9 +4837,7 @@ static bool load_city_name_list(struct section_file *file, } } - if (NULL != cities) { - free(cities); - } + free(cities); return ok; } @@ -5119,9 +5095,7 @@ static bool load_ruleset_nations(struct section_file *file, nation_rule_name(pnation), vec[j]); } } - if (NULL != vec) { - free(vec); - } + free(vec); if (nation_set_list_size(pnation->sets) < 1) { ruleset_error(NULL, LOG_ERROR, "Nation %s is not a member of any nation set", @@ -5152,9 +5126,7 @@ static bool load_ruleset_nations(struct section_file *file, nation_rule_name(pnation), vec[j]); } } - if (NULL != vec) { - free(vec); - } + free(vec); if (!ok) { break; } @@ -5438,9 +5410,7 @@ static bool load_ruleset_nations(struct section_file *file, nation_rule_name(pnation), vec[j]); } } - if (NULL != vec) { - free(vec); - } + free(vec); if (!ok) { break; } diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index b0d2516199..1ce120b470 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -501,57 +501,31 @@ static struct loaddata *loaddata_new(struct section_file *file) ****************************************************************************/ static void loaddata_destroy(struct loaddata *loading) { - if (loading->improvement.order != NULL) { - free(loading->improvement.order); - } + free(loading->improvement.order); - if (loading->technology.order != NULL) { - free(loading->technology.order); - } + free(loading->technology.order); - if (loading->activities.order != NULL) { - free(loading->activities.order); - } + free(loading->activities.order); - if (loading->trait.order != NULL) { - free(loading->trait.order); - } + free(loading->trait.order); - if (loading->extra.order != NULL) { - free(loading->extra.order); - } + free(loading->extra.order); - if (loading->multiplier.order != NULL) { - free(loading->multiplier.order); - } + free(loading->multiplier.order); - if (loading->special.order != NULL) { - free(loading->special.order); - } + free(loading->special.order); - if (loading->base.order != NULL) { - free(loading->base.order); - } + free(loading->base.order); - if (loading->road.order != NULL) { - free(loading->road.order); - } + free(loading->road.order); - if (loading->specialist.order != NULL) { - free(loading->specialist.order); - } + free(loading->specialist.order); - if (loading->ds_t.order != NULL) { - free(loading->ds_t.order); - } + free(loading->ds_t.order); - if (loading->coptions.order != NULL) { - free(loading->coptions.order); - } + free(loading->coptions.order); - if (loading->worked_tiles != NULL) { - free(loading->worked_tiles); - } + free(loading->worked_tiles); free(loading); } diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 1ef846627e..5e42468dc0 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -612,53 +612,29 @@ static struct loaddata *loaddata_new(struct section_file *file) ****************************************************************************/ static void loaddata_destroy(struct loaddata *loading) { - if (loading->improvement.order != NULL) { - free(loading->improvement.order); - } + free(loading->improvement.order); - if (loading->technology.order != NULL) { - free(loading->technology.order); - } + free(loading->technology.order); - if (loading->activities.order != NULL) { - free(loading->activities.order); - } + free(loading->activities.order); - if (loading->trait.order != NULL) { - free(loading->trait.order); - } + free(loading->trait.order); - if (loading->extra.order != NULL) { - free(loading->extra.order); - } + free(loading->extra.order); - if (loading->multiplier.order != NULL) { - free(loading->multiplier.order); - } + free(loading->multiplier.order); - if (loading->specialist.order != NULL) { - free(loading->specialist.order); - } + free(loading->specialist.order); - if (loading->action.order != NULL) { - free(loading->action.order); - } + free(loading->action.order); - if (loading->act_dec.order != NULL) { - free(loading->act_dec.order); - } + free(loading->act_dec.order); - if (loading->ssa.order != NULL) { - free(loading->ssa.order); - } + free(loading->ssa.order); - if (loading->coptions.order != NULL) { - free(loading->coptions.order); - } + free(loading->coptions.order); - if (loading->worked_tiles != NULL) { - free(loading->worked_tiles); - } + free(loading->worked_tiles); free(loading); } @@ -7407,9 +7383,7 @@ static void sg_save_researches(struct savedata *saving) secfile_insert_int_vec(saving->file, vlist_research, game.control.num_tech_types, "research.r%d.vbs", i); - if (vlist_research) { - free(vlist_research); - } + free(vlist_research); } technology_save(saving->file, "research.r%d.saved", i, presearch->researching_saved); diff --git a/tools/ruledit/effect_edit.cpp b/tools/ruledit/effect_edit.cpp index f773798c29..0061d721de 100644 --- a/tools/ruledit/effect_edit.cpp +++ b/tools/ruledit/effect_edit.cpp @@ -386,9 +386,7 @@ void effect_edit::multiplier_menu(QAction *action) void effect_edit::comment_given() { if (selected != nullptr) { - if (selected->rulesave.comment != NULL) { - free(selected->rulesave.comment); - } + free(selected->rulesave.comment); if (!comment->text().isEmpty()) { selected->rulesave.comment = fc_strdup(comment->text().toUtf8()); diff --git a/tools/ruledit/tab_misc.cpp b/tools/ruledit/tab_misc.cpp index 7a3902beb0..b5386f7069 100644 --- a/tools/ruledit/tab_misc.cpp +++ b/tools/ruledit/tab_misc.cpp @@ -501,9 +501,7 @@ void tab_misc::flush_widgets() df_bytes = desc_file->text().toUtf8(); game.server.ruledit.description_file = fc_strdup(df_bytes.data()); } else { - if (game.server.ruledit.description_file != NULL) { - free(game.server.ruledit.description_file); - } + free(game.server.ruledit.description_file); game.server.ruledit.description_file = NULL; } } diff --git a/utility/fc_cmdhelp.c b/utility/fc_cmdhelp.c index 909eac8c4b..bf86518d47 100644 --- a/utility/fc_cmdhelp.c +++ b/utility/fc_cmdhelp.c @@ -70,9 +70,7 @@ struct cmdhelp *cmdhelp_new(const char *cmdname) void cmdhelp_destroy(struct cmdhelp *pcmdhelp) { if (pcmdhelp) { - if (pcmdhelp->cmdname) { - free(pcmdhelp->cmdname); - } + free(pcmdhelp->cmdname); cmdarg_list_iterate(pcmdhelp->cmdarglist, pcmdarg) { cmdarg_destroy(pcmdarg); } cmdarg_list_iterate_end; @@ -163,12 +161,8 @@ static struct cmdarg *cmdarg_new(const char *shortarg, const char *longarg, static void cmdarg_destroy(struct cmdarg *pcmdarg) { if (pcmdarg) { - if (pcmdarg->longarg) { - free(pcmdarg->longarg); - } - if (pcmdarg->helpstr) { - free(pcmdarg->helpstr); - } + free(pcmdarg->longarg); + free(pcmdarg->helpstr); } free(pcmdarg); } diff --git a/utility/fc_cmdline.c b/utility/fc_cmdline.c index b7f96ce3f9..d39dc29d90 100644 --- a/utility/fc_cmdline.c +++ b/utility/fc_cmdline.c @@ -205,8 +205,6 @@ void free_tokens(char **tokens, size_t ntokens) size_t i; for (i = 0; i < ntokens; i++) { - if (tokens[i]) { - free(tokens[i]); - } + free(tokens[i]); } } diff --git a/utility/inputfile.c b/utility/inputfile.c index 3a9c1b91b3..72accf7e93 100644 --- a/utility/inputfile.c +++ b/utility/inputfile.c @@ -276,9 +276,7 @@ static void inf_close_partial(struct inputfile *inf) else if (fz_fclose(inf->fp) != 0) { log_error("Error closing %s", inf_filename(inf)); } - if (inf->filename) { - free(inf->filename); - } + free(inf->filename); inf->filename = NULL; astr_free(&inf->cur_line); astr_free(&inf->token); diff --git a/utility/registry_ini.c b/utility/registry_ini.c index 3fa17dcd9d..f3d6113b2c 100644 --- a/utility/registry_ini.c +++ b/utility/registry_ini.c @@ -3319,9 +3319,7 @@ void entry_destroy(struct entry *pentry) /* Common free. */ free(pentry->name); - if (NULL != pentry->comment) { - free(pentry->comment); - } + free(pentry->comment); free(pentry); } @@ -3424,9 +3422,7 @@ void entry_set_comment(struct entry *pentry, const char *comment) return; } - if (NULL != pentry->comment) { - free(pentry->comment); - } + free(pentry->comment); pentry->comment = (NULL != comment ? fc_strdup(comment) : NULL); } diff --git a/utility/section_file.c b/utility/section_file.c index bbf5bd9d48..9c0ab37a19 100644 --- a/utility/section_file.c +++ b/utility/section_file.c @@ -109,9 +109,7 @@ void secfile_destroy(struct section_file *secfile) section_list_destroy(secfile->sections); - if (NULL != secfile->name) { - free(secfile->name); - } + free(secfile->name); free(secfile); } diff --git a/utility/specvec.h b/utility/specvec.h index 7102873396..e8ae9dfc7f 100644 --- a/utility/specvec.h +++ b/utility/specvec.h @@ -121,9 +121,7 @@ static inline void SPECVEC_FOO(_vector_copy) (SPECVEC_VECTOR *to, static inline void SPECVEC_FOO(_vector_free) (SPECVEC_VECTOR *tthis) { - if (tthis->p) { - free(tthis->p); - } + free(tthis->p); SPECVEC_FOO(_vector_init)(tthis); } diff --git a/utility/string_vector.c b/utility/string_vector.c index b8bee73f63..4fd5621449 100644 --- a/utility/string_vector.c +++ b/utility/string_vector.c @@ -36,9 +36,7 @@ struct strvec { **************************************************************************/ static void string_free(char *string) { - if (string) { - free(string); - } + free(string); } /**********************************************************************//** diff --git a/utility/timing.c b/utility/timing.c index 441777bb9f..db6b2777b1 100644 --- a/utility/timing.c +++ b/utility/timing.c @@ -191,9 +191,7 @@ struct timer *timer_renew(struct timer *t, enum timer_timetype type, t->use = use; #ifdef FREECIV_DEBUG if (name != NULL) { - if (t->name != NULL) { - free(t->name); - } + free(t->name); t->name = fc_strdup(name); } #endif @@ -210,9 +208,7 @@ void timer_destroy(struct timer *t) if (t != NULL) { #ifdef FREECIV_DEBUG - if (t->name != NULL) { - free(t->name); - } + free(t->name); #endif /* FREECIV_DEBUG */ free(t);