Manage JavaInfo instances via new/delete

Change-Id: I10a113718e525b646c51aa8a19f9f2b75a36714a
This commit is contained in:
Stephan Bergmann 2016-03-10 16:47:16 +01:00
parent 624f9696a9
commit 81dd7115e8
4 changed files with 11 additions and 21 deletions

View File

@ -206,10 +206,8 @@ typedef enum _javaFrameworkError
<p> <p>
Instances of this struct are created by the plug-in libraries which are used by Instances of this struct are created by the plug-in libraries which are used by
this framework (jvmfwk/vendorplugin.h). The memory of the instances is created this framework (jvmfwk/vendorplugin.h). The contained members must be
by <code>rtl_allocateMemory</code> (rtl/alloc.h). Therefore, the memory must freed individually.
be freed by <code>rtl_freeMemory</code>. Also the contained members must be
freed particularly.
For convenience this API provides the function <code>jfw_freeJavaInfo</code> For convenience this API provides the function <code>jfw_freeJavaInfo</code>
which frees the objects properly. </p> which frees the objects properly. </p>
*/ */

View File

@ -146,9 +146,7 @@ OString getPluginJarPath(
JavaInfo* createJavaInfo(const rtl::Reference<VendorBase> & info) JavaInfo* createJavaInfo(const rtl::Reference<VendorBase> & info)
{ {
JavaInfo* pInfo = static_cast<JavaInfo*>(rtl_allocateMemory(sizeof(JavaInfo))); JavaInfo* pInfo = new JavaInfo;
if (pInfo == nullptr)
return nullptr;
OUString sVendor = info->getVendor(); OUString sVendor = info->getVendor();
pInfo->sVendor = sVendor.pData; pInfo->sVendor = sVendor.pData;
rtl_uString_acquire(sVendor.pData); rtl_uString_acquire(sVendor.pData);

View File

@ -977,9 +977,7 @@ JavaInfo * CNodeJavaInfo::makeJavaInfo() const
{ {
if (bNil || m_bEmptyNode) if (bNil || m_bEmptyNode)
return nullptr; return nullptr;
JavaInfo * pInfo = static_cast<JavaInfo*>(rtl_allocateMemory(sizeof(JavaInfo))); JavaInfo * pInfo = new JavaInfo;
if (pInfo == nullptr)
return nullptr;
memset(pInfo, 0, sizeof(JavaInfo)); memset(pInfo, 0, sizeof(JavaInfo));
pInfo->sVendor = sVendor.pData; pInfo->sVendor = sVendor.pData;
rtl_uString_acquire(pInfo->sVendor); rtl_uString_acquire(pInfo->sVendor);

View File

@ -655,7 +655,7 @@ void jfw_freeJavaInfo(JavaInfo *pInfo)
rtl_uString_release(pInfo->sLocation); rtl_uString_release(pInfo->sLocation);
rtl_uString_release(pInfo->sVersion); rtl_uString_release(pInfo->sVersion);
rtl_byte_sequence_release(pInfo->arVendorData); rtl_byte_sequence_release(pInfo->arVendorData);
rtl_freeMemory(pInfo); delete pInfo;
} }
javaFrameworkError jfw_getSelectedJRE(JavaInfo **ppInfo) javaFrameworkError jfw_getSelectedJRE(JavaInfo **ppInfo)
@ -1081,16 +1081,12 @@ JavaInfo * CJavaInfo::copyJavaInfo(const JavaInfo * pInfo)
{ {
if (pInfo == nullptr) if (pInfo == nullptr)
return nullptr; return nullptr;
JavaInfo* newInfo = JavaInfo* newInfo = new JavaInfo;
static_cast<JavaInfo*>(rtl_allocateMemory(sizeof(JavaInfo)));
if (newInfo)
{
memcpy(newInfo, pInfo, sizeof(JavaInfo)); memcpy(newInfo, pInfo, sizeof(JavaInfo));
rtl_uString_acquire(pInfo->sVendor); rtl_uString_acquire(pInfo->sVendor);
rtl_uString_acquire(pInfo->sLocation); rtl_uString_acquire(pInfo->sLocation);
rtl_uString_acquire(pInfo->sVersion); rtl_uString_acquire(pInfo->sVersion);
rtl_byte_sequence_acquire(pInfo->arVendorData); rtl_byte_sequence_acquire(pInfo->arVendorData);
}
return newInfo; return newInfo;
} }