From e219ad195c98b329f780d30f236a633846d7deca Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 1 May 2017 17:47:18 +0200 Subject: [PATCH] classify: Replace memfree by free free also accepts a nullptr argument, so the code can be simplified. Signed-off-by: Stefan Weil --- classify/cluster.cpp | 45 +++++++++++++++++----------------------- classify/kdtree.cpp | 7 +++---- classify/ocrfeatures.cpp | 3 +-- classify/protos.cpp | 5 ++--- 4 files changed, 25 insertions(+), 35 deletions(-) diff --git a/classify/cluster.cpp b/classify/cluster.cpp index 1f82349552..cbb74691aa 100644 --- a/classify/cluster.cpp +++ b/classify/cluster.cpp @@ -24,7 +24,6 @@ #include "matrix.h" #include "tprintf.h" #include "danerror.h" -#include "freelist.h" #include #define HOTELLING 1 // If true use Hotelling's test to decide where to split. @@ -546,7 +545,7 @@ LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config) { */ void FreeClusterer(CLUSTERER *Clusterer) { if (Clusterer != NULL) { - memfree (Clusterer->ParamDesc); + free(Clusterer->ParamDesc); if (Clusterer->KDTree != NULL) FreeKDTree (Clusterer->KDTree); if (Clusterer->Root != NULL) @@ -558,7 +557,7 @@ void FreeClusterer(CLUSTERER *Clusterer) { FreeBuckets(Clusterer->bucket_cache[d][c]); } - memfree(Clusterer); + free(Clusterer); } } // FreeClusterer @@ -593,19 +592,14 @@ void FreePrototype(void *arg) { //PROTOTYPE *Prototype) Prototype->Cluster->Prototype = FALSE; // deallocate the prototype statistics and then the prototype itself - if (Prototype->Distrib != NULL) - memfree (Prototype->Distrib); - if (Prototype->Mean != NULL) - memfree (Prototype->Mean); + free (Prototype->Distrib); + free (Prototype->Mean); if (Prototype->Style != spherical) { - if (Prototype->Variance.Elliptical != NULL) - memfree (Prototype->Variance.Elliptical); - if (Prototype->Magnitude.Elliptical != NULL) - memfree (Prototype->Magnitude.Elliptical); - if (Prototype->Weight.Elliptical != NULL) - memfree (Prototype->Weight.Elliptical); + free (Prototype->Variance.Elliptical); + free (Prototype->Magnitude.Elliptical); + free (Prototype->Weight.Elliptical); } - memfree(Prototype); + free(Prototype); } // FreePrototype /** @@ -756,7 +750,7 @@ void CreateClusterTree(CLUSTERER *Clusterer) { FreeKDTree(context.tree); Clusterer->KDTree = NULL; delete context.heap; - memfree(context.candidates); + free(context.candidates); } // CreateClusterTree /** @@ -1173,9 +1167,9 @@ PROTOTYPE *TestEllipticalProto(CLUSTERER *Clusterer, } Tsq += Delta[x] * temp; } - memfree(Covariance); - memfree(Inverse); - memfree(Delta); + free(Covariance); + free(Inverse); + free(Delta); // Changed this function to match the formula in // Statistical Methods in Medical Research p 473 // By Peter Armitage, Geoffrey Berry, J. N. S. Matthews. @@ -1485,7 +1479,7 @@ ComputeStatistics (inT16 N, PARAM_DESC ParamDesc[], CLUSTER * Cluster) { 1.0 / N); // release temporary memory and return - memfree(Distance); + free(Distance); return (Statistics); } // ComputeStatistics @@ -2157,10 +2151,10 @@ BOOL8 DistributionOK(BUCKETS *Buckets) { * @note History: 6/5/89, DSJ, Created. */ void FreeStatistics(STATISTICS *Statistics) { - memfree (Statistics->CoVariance); - memfree (Statistics->Min); - memfree (Statistics->Max); - memfree(Statistics); + free(Statistics->CoVariance); + free(Statistics->Min); + free(Statistics->Max); + free(Statistics); } // FreeStatistics /** @@ -2190,7 +2184,7 @@ void FreeCluster(CLUSTER *Cluster) { if (Cluster != NULL) { FreeCluster (Cluster->Left); FreeCluster (Cluster->Right); - memfree(Cluster); + free(Cluster); } } // FreeCluster @@ -2487,8 +2481,7 @@ CLUSTER * Cluster, FLOAT32 MaxIllegal) NumIllegalInCluster = 0; if (Clusterer->NumChar > NumFlags) { - if (CharFlags != NULL) - memfree(CharFlags); + free(CharFlags); NumFlags = Clusterer->NumChar; CharFlags = (BOOL8 *) Emalloc (NumFlags * sizeof (BOOL8)); } diff --git a/classify/kdtree.cpp b/classify/kdtree.cpp index 6ba7086d23..28bf935016 100644 --- a/classify/kdtree.cpp +++ b/classify/kdtree.cpp @@ -24,7 +24,6 @@ #include "kdtree.h" #include "const.h" #include "emalloc.h" -#include "freelist.h" #include #include @@ -349,7 +348,7 @@ void KDWalk(KDTREE *Tree, void_proc action, void *context) { */ void FreeKDTree(KDTREE *Tree) { FreeSubTree(Tree->Root.Left); - memfree(Tree); + free(Tree); } /* FreeKDTree */ @@ -389,7 +388,7 @@ KDNODE *MakeKDNode(KDTREE *tree, FLOAT32 Key[], void *Data, int Index) { /*---------------------------------------------------------------------------*/ void FreeKDNode(KDNODE *Node) { - memfree ((char *)Node); + free(Node); } @@ -555,6 +554,6 @@ void FreeSubTree(KDNODE *sub_tree) { if (sub_tree != NULL) { FreeSubTree(sub_tree->Left); FreeSubTree(sub_tree->Right); - memfree(sub_tree); + free(sub_tree); } } diff --git a/classify/ocrfeatures.cpp b/classify/ocrfeatures.cpp index dae1d6763c..2dfd693043 100644 --- a/classify/ocrfeatures.cpp +++ b/classify/ocrfeatures.cpp @@ -22,7 +22,6 @@ #include "emalloc.h" #include "callcpp.h" #include "danerror.h" -#include "freelist.h" #include "scanutils.h" #include @@ -75,7 +74,7 @@ void FreeFeatureSet(FEATURE_SET FeatureSet) { if (FeatureSet) { for (i = 0; i < FeatureSet->NumFeatures; i++) FreeFeature(FeatureSet->Features[i]); - memfree(FeatureSet); + free(FeatureSet); } } /* FreeFeatureSet */ diff --git a/classify/protos.cpp b/classify/protos.cpp index 6291f12cd4..0c5f0981e4 100644 --- a/classify/protos.cpp +++ b/classify/protos.cpp @@ -28,7 +28,6 @@ #include "protos.h" #include "const.h" #include "emalloc.h" -#include "freelist.h" #include "callcpp.h" #include "tprintf.h" #include "scanutils.h" @@ -230,11 +229,11 @@ void FreeClassFields(CLASS_TYPE Class) { if (Class) { if (Class->MaxNumProtos > 0) - memfree (Class->Prototypes); + free(Class->Prototypes); if (Class->MaxNumConfigs > 0) { for (i = 0; i < Class->NumConfigs; i++) FreeBitVector (Class->Configurations[i]); - memfree (Class->Configurations); + free(Class->Configurations); } } }