diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-04-13 15:19:17 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-04-13 17:32:43 +0200 |
commit | 626dec44e33727a56353efb7f4eee83e93bc2f3d (patch) | |
tree | 629bb290fee1689d1484d7c430b475da7082994e /jvmfwk/source/framework.cxx | |
parent | 6925007c2a86d45a8d71f08ef46e56bb3eda21e3 (diff) |
Use std::unique_ptr<JavaInfo> in jfw_plugin_getJavaInfosFromPath
...thereby fixing a memory leak
Change-Id: I1aa91eeb407987abcdaa5221f4abd447f881c5d2
Diffstat (limited to 'jvmfwk/source/framework.cxx')
-rw-r--r-- | jvmfwk/source/framework.cxx | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx index 63d5733f445a..0dd643d92d45 100644 --- a/jvmfwk/source/framework.cxx +++ b/jvmfwk/source/framework.cxx @@ -384,35 +384,28 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) // query PATH for Java installations if (!bInfoFound) { - std::vector<JavaInfo*> vecJavaInfosFromPath; + std::vector<std::unique_ptr<JavaInfo>> vecJavaInfosFromPath; if (jfw_plugin_getJavaInfosFromPath( versionInfos, vecJavaInfosFromPath, infos) == javaPluginError::NONE) { - std::vector<JavaInfo*>::const_iterator it = vecJavaInfosFromPath.begin(); - while(it != vecJavaInfosFromPath.end() && !bInfoFound) + for (auto & pJInfo: vecJavaInfosFromPath) { - JavaInfo* pJInfo = *it; - if (pJInfo != nullptr) + // if the current Java installation implements all required features: use it + if ((pJInfo->nFeatures & nFeatureFlags) == nFeatureFlags) { - // if the current Java installation implements all required features: use it - if ((pJInfo->nFeatures & nFeatureFlags) == nFeatureFlags) - { - aCurrentInfo.reset(pJInfo); - bInfoFound = true; - } - else if (!aCurrentInfo) - { - // current Java installation does not provide all features - // but no Java installation has been detected before - // -> remember the current one until one is found - // that provides all features - aCurrentInfo.reset(pJInfo); - } - else - delete pJInfo; + aCurrentInfo = std::move(pJInfo); + bInfoFound = true; + break; + } + else if (!aCurrentInfo) + { + // current Java installation does not provide all features + // but no Java installation has been detected before + // -> remember the current one until one is found + // that provides all features + aCurrentInfo = std::move(pJInfo); } - ++it; } } } |