Removed null checks before calls to delete and free (#5049)

This commit is contained in:
Roy Stewart 2021-02-13 13:06:26 -05:00 committed by GitHub
parent 92abbc42df
commit 08b3285722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 36 deletions

View File

@ -32,7 +32,7 @@ public:
/// Destructor to take care of the owned default value. /// Destructor to take care of the owned default value.
~Option() { ~Option() {
if (_default != nullptr) delete _default; delete _default;
_default = nullptr; _default = nullptr;
} }

View File

@ -29,14 +29,11 @@ void
stl_invalidate_shared_vertices(stl_file *stl) { stl_invalidate_shared_vertices(stl_file *stl) {
if (stl->error) return; if (stl->error) return;
if (stl->v_indices != NULL) { free(stl->v_indices);
free(stl->v_indices); stl->v_indices = NULL;
stl->v_indices = NULL;
} free(stl->v_shared);
if (stl->v_shared != NULL) { stl->v_shared = NULL;
free(stl->v_shared);
stl->v_shared = NULL;
}
} }
void void

View File

@ -437,13 +437,9 @@ void
stl_close(stl_file *stl) { stl_close(stl_file *stl) {
if (stl->error) return; if (stl->error) return;
if(stl->neighbors_start != NULL) free(stl->neighbors_start);
free(stl->neighbors_start); free(stl->facet_start);
if(stl->facet_start != NULL) free(stl->v_indices);
free(stl->facet_start); free(stl->v_shared);
if(stl->v_indices != NULL)
free(stl->v_indices);
if(stl->v_shared != NULL)
free(stl->v_shared);
} }

View File

@ -207,8 +207,7 @@ ConfigOptionDef::ConfigOptionDef(const ConfigOptionDef &other)
ConfigOptionDef::~ConfigOptionDef() ConfigOptionDef::~ConfigOptionDef()
{ {
if (this->default_value != nullptr) delete this->default_value;
delete this->default_value;
} }
std::vector<std::string> std::vector<std::string>
@ -711,7 +710,7 @@ DynamicConfig::swap(DynamicConfig &other)
DynamicConfig::~DynamicConfig () { DynamicConfig::~DynamicConfig () {
for (t_options_map::iterator it = this->options.begin(); it != this->options.end(); ++it) { for (t_options_map::iterator it = this->options.begin(); it != this->options.end(); ++it) {
ConfigOption* opt = it->second; ConfigOption* opt = it->second;
if (opt != NULL) delete opt; delete opt;
} }
} }

View File

@ -16,18 +16,15 @@ AvoidCrossingPerimeters::AvoidCrossingPerimeters()
AvoidCrossingPerimeters::~AvoidCrossingPerimeters() AvoidCrossingPerimeters::~AvoidCrossingPerimeters()
{ {
if (this->_external_mp != NULL) delete this->_external_mp;
delete this->_external_mp;
if (this->_layer_mp != NULL) delete this->_layer_mp;
delete this->_layer_mp;
} }
void void
AvoidCrossingPerimeters::init_external_mp(const ExPolygons &islands) AvoidCrossingPerimeters::init_external_mp(const ExPolygons &islands)
{ {
if (this->_external_mp != NULL) delete this->_external_mp;
delete this->_external_mp;
this->_external_mp = new MotionPlanner(islands); this->_external_mp = new MotionPlanner(islands);
} }
@ -35,8 +32,7 @@ AvoidCrossingPerimeters::init_external_mp(const ExPolygons &islands)
void void
AvoidCrossingPerimeters::init_layer_mp(const ExPolygons &islands) AvoidCrossingPerimeters::init_layer_mp(const ExPolygons &islands)
{ {
if (this->_layer_mp != NULL) delete this->_layer_mp;
delete this->_layer_mp;
this->_layer_mp = new MotionPlanner(islands); this->_layer_mp = new MotionPlanner(islands);
} }

View File

@ -145,9 +145,7 @@ Model::add_material(t_model_material_id material_id, const ModelMaterial &other)
{ {
// delete existing material if any // delete existing material if any
ModelMaterial* material = this->get_material(material_id); ModelMaterial* material = this->get_material(material_id);
if (material != NULL) { delete material;
delete material;
}
// set new material // set new material
material = new ModelMaterial(this, other); material = new ModelMaterial(this, other);

View File

@ -1650,7 +1650,7 @@ TriangleMeshSlicer<A>::TriangleMeshSlicer(TriangleMesh* _mesh) : mesh(_mesh), v_
template <Axis A> template <Axis A>
TriangleMeshSlicer<A>::~TriangleMeshSlicer() TriangleMeshSlicer<A>::~TriangleMeshSlicer()
{ {
if (this->v_scaled_shared != NULL) free(this->v_scaled_shared); free(this->v_scaled_shared);
} }
template class TriangleMeshSlicer<X>; template class TriangleMeshSlicer<X>;

View File

@ -162,10 +162,8 @@ class Filler
public: public:
Filler() : fill(NULL) {}; Filler() : fill(NULL) {};
~Filler() { ~Filler() {
if (fill != NULL) { delete fill;
delete fill; fill = NULL;
fill = NULL;
}
}; };
Fill* fill; Fill* fill;
}; };