From 14265f0346f5118cbe6a935fd1b9d629e6664c70 Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Sat, 27 Dec 2014 22:31:32 +0100 Subject: [PATCH] Fix some cppcheck reports (part3) - (error) Resource leak: f - (style) Statements following return, break, continue, goto or throw will never be executed (1 of them) - (style) Unused variable (most of them) --- opencog/comboreduct/type_checker/type_tree.cc | 1 - opencog/dynamics/attention/ImportanceDiffusionAgent.cc | 1 - opencog/dynamics/attention/ImportanceSpreadingAgent.cc | 1 - opencog/embodiment/Control/OperationalAvatarController/Pet.cc | 1 - .../embodiment/Control/PerceptionActionInterface/PAIUtils.cc | 2 +- opencog/embodiment/WorldWrapper/PAIWorldWrapper.cc | 3 --- opencog/guile/load-file.cc | 1 - opencog/learning/moses/main/eval-diversity.cc | 1 - opencog/persist/file/SavingLoading.cc | 1 + opencog/server/ListRequest.cc | 1 - opencog/visualization/ubigraph/Ubigrapher.cc | 4 +--- 11 files changed, 3 insertions(+), 14 deletions(-) diff --git a/opencog/comboreduct/type_checker/type_tree.cc b/opencog/comboreduct/type_checker/type_tree.cc index 027d58c2883..9df11f4d44b 100644 --- a/opencog/comboreduct/type_checker/type_tree.cc +++ b/opencog/comboreduct/type_checker/type_tree.cc @@ -872,7 +872,6 @@ void reduce_type_tree(type_tree& tt, type_tree_pre_it it, else if (*it == id::union_type) { OC_ASSERT(!it.is_childless(), "union_type must have at least a child"); - type_tree_seq utt; //apply reduce recursively to the children of the union for (type_tree_sib_it sib = it.begin(); sib != it.end(); ++sib) { reduce_type_tree(tt, type_tree_pre_it(sib), arg_types, diff --git a/opencog/dynamics/attention/ImportanceDiffusionAgent.cc b/opencog/dynamics/attention/ImportanceDiffusionAgent.cc index 0e95ed330ff..c51e069ea51 100644 --- a/opencog/dynamics/attention/ImportanceDiffusionAgent.cc +++ b/opencog/dynamics/attention/ImportanceDiffusionAgent.cc @@ -352,7 +352,6 @@ void ImportanceDiffusionAgent::spreadImportance() int totalDiffusionAtoms = 0; std::vector links; - std::vector::iterator hi; std::back_insert_iterator< std::vector > out_hi(links); log->debug("Begin diffusive importance spread."); diff --git a/opencog/dynamics/attention/ImportanceSpreadingAgent.cc b/opencog/dynamics/attention/ImportanceSpreadingAgent.cc index 6186f88e4e5..fec90f0a5d1 100644 --- a/opencog/dynamics/attention/ImportanceSpreadingAgent.cc +++ b/opencog/dynamics/attention/ImportanceSpreadingAgent.cc @@ -103,7 +103,6 @@ void ImportanceSpreadingAgent::spreadImportance() // to avoid retrieving them twice int ImportanceSpreadingAgent::sumTotalDifference(Handle source, HandleSeq& links) { - std::vector targets; int totalDifference = 0; // sum total difference foreach(Handle handle, links) { diff --git a/opencog/embodiment/Control/OperationalAvatarController/Pet.cc b/opencog/embodiment/Control/OperationalAvatarController/Pet.cc index 8d236f87d62..813b8b7caec 100644 --- a/opencog/embodiment/Control/OperationalAvatarController/Pet.cc +++ b/opencog/embodiment/Control/OperationalAvatarController/Pet.cc @@ -994,7 +994,6 @@ void Pet::getAllActionsDoneInATrickAtTime(const Temporal& time, HandleSeq& actio true); foreach(Handle learningSessionHandle, learningSessionHandles) { if (atomSpace->getArity(learningSessionHandle) > 1) { - std::set actionHandles; std::vector learningSessionIntervals; // Get temporal info for all the Handles that pertain to this // trick diff --git a/opencog/embodiment/Control/PerceptionActionInterface/PAIUtils.cc b/opencog/embodiment/Control/PerceptionActionInterface/PAIUtils.cc index 127f7cbe2a4..ee4393a9f44 100644 --- a/opencog/embodiment/Control/PerceptionActionInterface/PAIUtils.cc +++ b/opencog/embodiment/Control/PerceptionActionInterface/PAIUtils.cc @@ -111,8 +111,8 @@ std::string PAIUtils::getSerializedXMLString(XERCES_CPP_NAMESPACE::DOMDocument * throw opencog::RuntimeException(TRACE_INFO, "PAIUtils - Out of Memory Exception!"); } catch (const XERCES_CPP_NAMESPACE::XMLException& toCatch) { char* message = XERCES_CPP_NAMESPACE::XMLString::transcode(toCatch.getMessage()); - throw opencog::RuntimeException(TRACE_INFO, "PAIUtils - Exception message is: %s.", message); XERCES_CPP_NAMESPACE::XMLString::release(&message); + throw opencog::RuntimeException(TRACE_INFO, "PAIUtils - Exception message is: %s.", message); } return result; diff --git a/opencog/embodiment/WorldWrapper/PAIWorldWrapper.cc b/opencog/embodiment/WorldWrapper/PAIWorldWrapper.cc index 2cd39388d2c..0f4b6528784 100644 --- a/opencog/embodiment/WorldWrapper/PAIWorldWrapper.cc +++ b/opencog/embodiment/WorldWrapper/PAIWorldWrapper.cc @@ -813,9 +813,6 @@ bool PAIWorldWrapper::build_goto_plan(Handle goalHandle, if (config().get_bool("ENABLE_UNITY_CONNECTOR")) { - std::vector actions; - - float speed = ( walkSpeed != 0 ) ? walkSpeed : pai.getAvatarInterface().computeWalkingSpeed(); diff --git a/opencog/guile/load-file.cc b/opencog/guile/load-file.cc index 078a5d637cc..d63ef0f4c8c 100644 --- a/opencog/guile/load-file.cc +++ b/opencog/guile/load-file.cc @@ -106,7 +106,6 @@ void load_scm_files_from_config(AtomSpace& atomSpace, std::vector scm_modules; tokenize(config()["SCM_PRELOAD"], std::back_inserter(scm_modules), ", "); - std::vector::const_iterator it; for (const std::string& scm_module : scm_modules) load_scm_file_relative(atomSpace, scm_module, search_paths); } diff --git a/opencog/learning/moses/main/eval-diversity.cc b/opencog/learning/moses/main/eval-diversity.cc index b95a1d0c7ff..9030df0fa19 100644 --- a/opencog/learning/moses/main/eval-diversity.cc +++ b/opencog/learning/moses/main/eval-diversity.cc @@ -150,7 +150,6 @@ int main(int argc, char** argv) if (!edp.moses_files.empty()) { // load the bscores - vector bscores; vector bcts; for (const string& file : edp.moses_files) { ifstream in(file); diff --git a/opencog/persist/file/SavingLoading.cc b/opencog/persist/file/SavingLoading.cc index 6f3ac9a00bd..c86296c7975 100644 --- a/opencog/persist/file/SavingLoading.cc +++ b/opencog/persist/file/SavingLoading.cc @@ -283,6 +283,7 @@ void SavingLoading::load(const char *fileName, // reads the total number of atoms. Just an idea for now. int atomCount = 0; if ( fread(&atomCount, sizeof(int), 1, f) != 1 ) { + fclose(f); throw RuntimeException(TRACE_INFO, "SavingLoading - failed to read."); } diff --git a/opencog/server/ListRequest.cc b/opencog/server/ListRequest.cc index 826e036034b..ea0216a6633 100644 --- a/opencog/server/ListRequest.cc +++ b/opencog/server/ListRequest.cc @@ -54,7 +54,6 @@ bool ListRequest::execute() Handle handle = Handle::UNDEFINED; bool subtypes = false; AtomSpace& as = _cogserver.getAtomSpace(); - std::ostringstream err; if (0 == _parameters.size()) { _error << "Error: option required" << std::endl; diff --git a/opencog/visualization/ubigraph/Ubigrapher.cc b/opencog/visualization/ubigraph/Ubigrapher.cc index dc97af10c7f..f7856851437 100644 --- a/opencog/visualization/ubigraph/Ubigrapher.cc +++ b/opencog/visualization/ubigraph/Ubigrapher.cc @@ -243,7 +243,7 @@ void Ubigrapher::updateColourOfHandle(Handle h, property_t p, unsigned char star unsigned char val[3]; float scaler = 0.0f; int j; - std::ostringstream ost, ost2; + std::ostringstream ost; unsigned char diff[3]; float multiplierForTV = 10.0f; @@ -292,8 +292,6 @@ void Ubigrapher::updateColourOfHandle(Handle h, property_t p, unsigned char star ubigraph_set_vertex_attribute(h.value(), "color", ost.str().c_str()); } else { ubigraph_set_vertex_attribute(h.value(), "color", ost.str().c_str()); -// ost2 << 1.0 + 4 * space->getNormalisedZeroToOneSTI(h,false,true); -// ubigraph_set_vertex_attribute(h.value(), "size", ost2.str().c_str()); } }