Fix memory leaks
Change-Id: If9f7dc4a28d5e005959f0d4a0a2ed317b699f292
This commit is contained in:
@@ -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
|
||||
|
@@ -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&)
|
||||
{
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user