summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-03-10 21:40:45 +0100
committerStephan Bergmann <sbergman@redhat.com>2016-03-10 21:43:13 +0100
commiteee4dd746ea3fc09d51d008446ec82e3de456eed (patch)
treea883cc057f95a72ceb808ee5e4cbd8e6d98bb7f3
parent8e9a7cac42d554402a6ead3a83ae8b7defc9247b (diff)
Fix memory leaks
Change-Id: If9f7dc4a28d5e005959f0d4a0a2ed317b699f292
-rw-r--r--include/jvmfwk/framework.hxx20
-rw-r--r--jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx15
-rw-r--r--stoc/source/javavm/javavm.cxx29
3 files changed, 32 insertions, 32 deletions
diff --git a/include/jvmfwk/framework.hxx b/include/jvmfwk/framework.hxx
index e88ae4be0b15..9a3b88479ab7 100644
--- a/include/jvmfwk/framework.hxx
+++ b/include/jvmfwk/framework.hxx
@@ -255,6 +255,26 @@ struct JavaInfo
rtl::ByteSequence arVendorData;
};
+namespace jfw {
+
+struct JavaInfoGuard {
+ JavaInfoGuard(JavaInfoGuard &) = delete;
+ void operator =(JavaInfoGuard) = delete;
+
+ JavaInfoGuard(): info(nullptr) {}
+
+ ~JavaInfoGuard() { delete info; }
+
+ void clear() {
+ delete info;
+ info = nullptr;
+ }
+
+ JavaInfo * info;
+};
+
+}
+
/** compares two <code>JavaInfo</code> objects for equality.
<p>Two <code>JavaInfo</code> objects are said to be equal if the contained
diff --git a/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx b/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx
index ea2f846e9f25..9daf5740f1ba 100644
--- a/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx
+++ b/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx
@@ -64,8 +64,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
return -1;
}
- JavaInfo * pInfo = nullptr;
- errcode = jfw_getSelectedJRE( & pInfo);
+ jfw::JavaInfoGuard pInfo;
+ errcode = jfw_getSelectedJRE(&pInfo.info);
if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS)
{
@@ -73,19 +73,19 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
return -1;
}
- if (pInfo == nullptr)
+ if (pInfo.info == nullptr)
{
- if (!findAndSelect(&pInfo))
+ if (!findAndSelect(&pInfo.info))
return -1;
}
else
{
//check if the JRE was not uninstalled
sal_Bool bExist = sal_False;
- errcode = jfw_existJRE(pInfo, &bExist);
+ errcode = jfw_existJRE(pInfo.info, &bExist);
if (errcode == JFW_E_NONE)
{
- if (!bExist && !findAndSelect(&pInfo))
+ if (!bExist && !findAndSelect(&pInfo.info))
return -1;
}
else
@@ -95,9 +95,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
}
}
- OString sPaths = getLD_LIBRARY_PATH(pInfo->arVendorData);
+ OString sPaths = getLD_LIBRARY_PATH(pInfo.info->arVendorData);
fprintf(stdout, "%s\n", sPaths.getStr());
- delete pInfo;
}
catch (const std::exception&)
{
diff --git a/stoc/source/javavm/javavm.cxx b/stoc/source/javavm/javavm.cxx
index ab72925cbefb..0e6577364fe2 100644
--- a/stoc/source/javavm/javavm.cxx
+++ b/stoc/source/javavm/javavm.cxx
@@ -657,23 +657,6 @@ JavaVirtualMachine::getSupportedServiceNames()
return serviceGetSupportedServiceNames();
}
-namespace {
-
-struct JavaInfoGuard: private boost::noncopyable {
- JavaInfoGuard(): info(nullptr) {}
-
- ~JavaInfoGuard() { delete info; }
-
- void clear() {
- delete info;
- info = nullptr;
- }
-
- JavaInfo * info;
-};
-
-}
-
css::uno::Any SAL_CALL
JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
throw (css::uno::RuntimeException, std::exception)
@@ -698,7 +681,7 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
if (aId != aProcessId)
return css::uno::Any();
- JavaInfoGuard info;
+ jfw::JavaInfoGuard info;
while (!m_xVirtualMachine.is()) // retry until successful
{
// This is the second attempt to create Java. m_bDontCreateJvm is
@@ -816,14 +799,14 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
//we search another one. As long as there is a javaldx, we should
//never come into this situation. javaldx checks always if the JRE
//still exist.
- JavaInfo * pJavaInfo = nullptr;
- if (JFW_E_NONE == jfw_getSelectedJRE(&pJavaInfo))
+ jfw::JavaInfoGuard pJavaInfo;
+ if (JFW_E_NONE == jfw_getSelectedJRE(&pJavaInfo.info))
{
sal_Bool bExist = sal_False;
- if (JFW_E_NONE == jfw_existJRE(pJavaInfo, &bExist))
+ if (JFW_E_NONE == jfw_existJRE(pJavaInfo.info, &bExist))
{
if (!bExist
- && ! (pJavaInfo->nRequirements & JFW_REQUIRE_NEEDRESTART))
+ && ! (pJavaInfo.info->nRequirements & JFW_REQUIRE_NEEDRESTART))
{
info.clear();
javaFrameworkError errFind = jfw_findAndSelectJRE(
@@ -836,8 +819,6 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
}
}
- delete pJavaInfo;
-
//Error: %PRODUCTNAME requires a Java
//runtime environment (JRE) to perform this task. The selected JRE
//is defective. Please select another version or install a new JRE