From 81dd7115e8da9a365a2d26e225f6ec4d2d8ccb5f Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 10 Mar 2016 16:47:16 +0100 Subject: Manage JavaInfo instances via new/delete Change-Id: I10a113718e525b646c51aa8a19f9f2b75a36714a --- include/jvmfwk/framework.hxx | 6 ++---- jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 4 +--- jvmfwk/source/elements.cxx | 4 +--- jvmfwk/source/framework.cxx | 18 +++++++----------- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/include/jvmfwk/framework.hxx b/include/jvmfwk/framework.hxx index f55676c60925..6ee43200d983 100644 --- a/include/jvmfwk/framework.hxx +++ b/include/jvmfwk/framework.hxx @@ -206,10 +206,8 @@ typedef enum _javaFrameworkError

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 - by rtl_allocateMemory (rtl/alloc.h). Therefore, the memory must - be freed by rtl_freeMemory. Also the contained members must be - freed particularly. + this framework (jvmfwk/vendorplugin.h). The contained members must be + freed individually. For convenience this API provides the function jfw_freeJavaInfo which frees the objects properly.

*/ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx index 89e1a49bd1ed..e69420334736 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx @@ -146,9 +146,7 @@ OString getPluginJarPath( JavaInfo* createJavaInfo(const rtl::Reference & info) { - JavaInfo* pInfo = static_cast(rtl_allocateMemory(sizeof(JavaInfo))); - if (pInfo == nullptr) - return nullptr; + JavaInfo* pInfo = new JavaInfo; OUString sVendor = info->getVendor(); pInfo->sVendor = sVendor.pData; rtl_uString_acquire(sVendor.pData); diff --git a/jvmfwk/source/elements.cxx b/jvmfwk/source/elements.cxx index 3e9f478c58ea..60a1fa5cbe21 100644 --- a/jvmfwk/source/elements.cxx +++ b/jvmfwk/source/elements.cxx @@ -977,9 +977,7 @@ JavaInfo * CNodeJavaInfo::makeJavaInfo() const { if (bNil || m_bEmptyNode) return nullptr; - JavaInfo * pInfo = static_cast(rtl_allocateMemory(sizeof(JavaInfo))); - if (pInfo == nullptr) - return nullptr; + JavaInfo * pInfo = new JavaInfo; memset(pInfo, 0, sizeof(JavaInfo)); pInfo->sVendor = sVendor.pData; rtl_uString_acquire(pInfo->sVendor); diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx index f28092a59b28..e70e831e54b2 100644 --- a/jvmfwk/source/framework.cxx +++ b/jvmfwk/source/framework.cxx @@ -655,7 +655,7 @@ void jfw_freeJavaInfo(JavaInfo *pInfo) rtl_uString_release(pInfo->sLocation); rtl_uString_release(pInfo->sVersion); rtl_byte_sequence_release(pInfo->arVendorData); - rtl_freeMemory(pInfo); + delete pInfo; } javaFrameworkError jfw_getSelectedJRE(JavaInfo **ppInfo) @@ -1081,16 +1081,12 @@ JavaInfo * CJavaInfo::copyJavaInfo(const JavaInfo * pInfo) { if (pInfo == nullptr) return nullptr; - JavaInfo* newInfo = - static_cast(rtl_allocateMemory(sizeof(JavaInfo))); - if (newInfo) - { - memcpy(newInfo, pInfo, sizeof(JavaInfo)); - rtl_uString_acquire(pInfo->sVendor); - rtl_uString_acquire(pInfo->sLocation); - rtl_uString_acquire(pInfo->sVersion); - rtl_byte_sequence_acquire(pInfo->arVendorData); - } + JavaInfo* newInfo = new JavaInfo; + memcpy(newInfo, pInfo, sizeof(JavaInfo)); + rtl_uString_acquire(pInfo->sVendor); + rtl_uString_acquire(pInfo->sLocation); + rtl_uString_acquire(pInfo->sVersion); + rtl_byte_sequence_acquire(pInfo->arVendorData); return newInfo; } -- cgit