From 41a20d3b3750fa6eeb8061af9dd25723d4698feb Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 13 Apr 2017 12:08:05 +0200 Subject: More std::unique_ptr lifecycle management Change-Id: If53347633ec4b2f8c2b221ba2057e0c38fa97b67 --- jvmfwk/inc/elements.hxx | 7 +++++-- jvmfwk/source/elements.cxx | 20 ++++++++------------ jvmfwk/source/framework.cxx | 4 ++-- 3 files changed, 15 insertions(+), 16 deletions(-) (limited to 'jvmfwk') diff --git a/jvmfwk/inc/elements.hxx b/jvmfwk/inc/elements.hxx index f4766a5c92bd..047c5aab85bc 100644 --- a/jvmfwk/inc/elements.hxx +++ b/jvmfwk/inc/elements.hxx @@ -19,6 +19,9 @@ #ifndef INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX #define INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX +#include + +#include #include #include "jvmfwk/framework.hxx" #include "fwkutil.hxx" @@ -98,7 +101,7 @@ public: /** returns NULL if javaInfo is nil. */ - JavaInfo * makeJavaInfo() const; + std::unique_ptr makeJavaInfo() const; }; /** this class represents the java settings based on a particular @@ -294,7 +297,7 @@ public: which needs to be freed by the caller. If both, user and share settings are nil, then NULL is returned. */ - JavaInfo * createJavaInfo() const; + std::unique_ptr createJavaInfo() const; /** returns the value of the attribute /java/javaInfo[@vendorUpdate]. */ diff --git a/jvmfwk/source/elements.cxx b/jvmfwk/source/elements.cxx index 4da38c001ed9..353eab37ba6f 100644 --- a/jvmfwk/source/elements.cxx +++ b/jvmfwk/source/elements.cxx @@ -20,6 +20,7 @@ #include #include +#include #include "elements.hxx" #include "osl/mutex.hxx" @@ -925,19 +926,14 @@ void CNodeJavaInfo::writeToNode(xmlDoc* pDoc, xmlAddChild(pJavaInfoNode, nodeCrLf); } -JavaInfo * CNodeJavaInfo::makeJavaInfo() const +std::unique_ptr CNodeJavaInfo::makeJavaInfo() const { if (bNil || m_bEmptyNode) - return nullptr; - JavaInfo * pInfo = new JavaInfo; - memset(pInfo, 0, sizeof(JavaInfo)); - pInfo->sVendor = sVendor; - pInfo->sLocation = sLocation; - pInfo->sVersion = sVersion; - pInfo->nFeatures = nFeatures; - pInfo->nRequirements = nRequirements; - pInfo->arVendorData = arVendorData; - return pInfo; + return std::unique_ptr(); + return std::unique_ptr( + new JavaInfo{ + sVendor, sLocation, sVersion, nFeatures, nRequirements, + arVendorData}); } @@ -1002,7 +998,7 @@ void MergedSettings::merge(const NodeJava & share, const NodeJava & user) } -JavaInfo * MergedSettings::createJavaInfo() const +std::unique_ptr MergedSettings::createJavaInfo() const { return m_javaInfo.makeJavaInfo(); } diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx index 42d99557fc0b..b4e94e0d93bf 100644 --- a/jvmfwk/source/framework.cxx +++ b/jvmfwk/source/framework.cxx @@ -213,7 +213,7 @@ javaFrameworkError jfw_startVM( const jfw::MergedSettings settings; if (!settings.getEnabled()) return JFW_E_JAVA_DISABLED; - aInfo.reset(settings.createJavaInfo()); + aInfo = settings.createJavaInfo(); //check if a Java has ever been selected if (!aInfo) return JFW_E_NO_SELECT; @@ -650,7 +650,7 @@ javaFrameworkError jfw_getSelectedJRE(std::unique_ptr *ppInfo) } const jfw::MergedSettings settings; - ppInfo->reset(settings.createJavaInfo()); + *ppInfo = settings.createJavaInfo(); if (!*ppInfo) { return JFW_E_NONE; -- cgit