This is an automated email from the ASF dual-hosted git repository.
bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push:
new d3a185b GEODE-7476: Fix several leaks in native client (#553)
d3a185b is described below
commit d3a185b8b326f5223ca2e9d948a4dcc79b092536
Author: Alberto Gomez <[email protected]>
AuthorDate: Thu Nov 21 22:23:02 2019 +0100
GEODE-7476: Fix several leaks in native client (#553)
* Fixed most leaks found when running the new integration
tests under valgrind.
---
cppcache/src/BucketServerLocation.hpp | 30 ++++----
cppcache/src/CachePerfStats.hpp | 14 +---
cppcache/src/CqQueryVsdStats.cpp | 4 +-
cppcache/src/CqServiceVsdStats.cpp | 4 +-
cppcache/src/ExecutionImpl.cpp | 6 +-
cppcache/src/ExecutionImpl.hpp | 7 +-
cppcache/src/ExpiryTaskManager.cpp | 11 ++-
cppcache/src/PoolStatistics.cpp | 4 +-
cppcache/src/RegionStats.cpp | 4 +-
cppcache/src/TcrConnection.cpp | 33 ++++-----
cppcache/src/TcrConnectionManager.cpp | 3 +-
cppcache/src/TcrConnectionManager.hpp | 2 +-
cppcache/src/TcrMessage.cpp | 6 +-
cppcache/src/TcrMessage.hpp | 4 +-
cppcache/src/ThinClientPoolDM.cpp | 35 ++++-----
cppcache/src/ThinClientRegion.cpp | 13 ++--
cppcache/src/ThinClientRegion.hpp | 2 +-
cppcache/src/statistics/AtomicStatisticsImpl.cpp | 51 +++++++-------
cppcache/src/statistics/AtomicStatisticsImpl.hpp | 41 +++++++----
cppcache/src/statistics/GeodeStatisticsFactory.cpp | 22 +++---
cppcache/src/statistics/GeodeStatisticsFactory.hpp | 59 +++++++---------
cppcache/src/statistics/OsStatisticsImpl.cpp | 55 ++++++++-------
cppcache/src/statistics/OsStatisticsImpl.hpp | 41 +++++++----
cppcache/src/statistics/StatArchiveWriter.cpp | 38 +++++-----
cppcache/src/statistics/StatArchiveWriter.hpp | 15 ++--
cppcache/src/statistics/StatSamplerStats.cpp | 7 +-
cppcache/src/statistics/StatSamplerStats.hpp | 1 -
.../src/statistics/StatisticDescriptorImpl.cpp | 82 ++++++++--------------
.../src/statistics/StatisticDescriptorImpl.hpp | 42 +++++------
cppcache/src/statistics/Statistics.cpp | 37 +++++++---
cppcache/src/statistics/Statistics.hpp | 29 ++++----
cppcache/src/statistics/StatisticsFactory.hpp | 46 ++++++------
cppcache/src/statistics/StatisticsType.hpp | 10 ++-
cppcache/src/statistics/StatisticsTypeImpl.cpp | 51 ++++----------
cppcache/src/statistics/StatisticsTypeImpl.hpp | 17 +++--
tests/cpp/testobject/PdxType.cpp | 5 +-
tests/cpp/testobject/PdxType.hpp | 23 ++++--
37 files changed, 418 insertions(+), 436 deletions(-)
diff --git a/cppcache/src/BucketServerLocation.hpp
b/cppcache/src/BucketServerLocation.hpp
index 9c44f2a..5322ef4 100644
--- a/cppcache/src/BucketServerLocation.hpp
+++ b/cppcache/src/BucketServerLocation.hpp
@@ -71,19 +71,16 @@ class BucketServerLocation : public ServerLocation {
m_isPrimary(isPrimary),
m_version(version) {
int32_t size = static_cast<int32_t>(serverGroups.size());
- std::shared_ptr<CacheableString>* ptrArr = nullptr;
if (size > 0) {
- ptrArr = new std::shared_ptr<CacheableString>[size];
- for (int i = 0; i < size; i++) {
- ptrArr[i] = CacheableString::create(serverGroups[i]);
+ std::vector<std::shared_ptr<CacheableString>> tmpServerGroups;
+ tmpServerGroups.reserve(size);
+ for (auto&& serverGroup : serverGroups) {
+ tmpServerGroups.emplace_back(CacheableString::create(serverGroup));
}
- }
- if (size > 0) {
if (size > 0x7f) {
// TODO: should fail here since m_numServerGroups is int8_t?
}
- m_serverGroups = CacheableStringArray::create(
- std::vector<std::shared_ptr<CacheableString>>(ptrArr, ptrArr +
size));
+ m_serverGroups =
CacheableStringArray::create(std::move(tmpServerGroups));
m_numServerGroups = static_cast<int8_t>(size);
} else {
m_serverGroups = nullptr;
@@ -104,8 +101,8 @@ class BucketServerLocation : public ServerLocation {
output.write(m_version);
output.write(static_cast<int8_t>(m_numServerGroups));
if (m_numServerGroups > 0) {
- for (int i = 0; i < m_numServerGroups; i++) {
- output.writeObject(m_serverGroups->value()[i]);
+ for (auto&& serverGroup : m_serverGroups->value()) {
+ output.writeObject(serverGroup);
}
}
}
@@ -116,17 +113,14 @@ class BucketServerLocation : public ServerLocation {
m_isPrimary = input.readBoolean();
m_version = input.read();
m_numServerGroups = input.read();
- std::shared_ptr<CacheableString>* serverGroups = nullptr;
+
if (m_numServerGroups > 0) {
- serverGroups = new std::shared_ptr<CacheableString>[m_numServerGroups];
+ std::vector<std::shared_ptr<CacheableString>> serverGroups;
+ serverGroups.reserve(m_numServerGroups);
for (int i = 0; i < m_numServerGroups; i++) {
- serverGroups[i] = CacheableString::create(input.readString());
+ serverGroups.emplace_back(CacheableString::create(input.readString()));
}
- }
- if (m_numServerGroups > 0) {
- m_serverGroups = CacheableStringArray::create(
- std::vector<std::shared_ptr<CacheableString>>(
- serverGroups, serverGroups + m_numServerGroups));
+ m_serverGroups = CacheableStringArray::create(std::move(serverGroups));
}
}
diff --git a/cppcache/src/CachePerfStats.hpp b/cppcache/src/CachePerfStats.hpp
index 3bd633b..0096562 100644
--- a/cppcache/src/CachePerfStats.hpp
+++ b/cppcache/src/CachePerfStats.hpp
@@ -42,7 +42,7 @@ class APACHE_GEODE_EXPORT CachePerfStats {
if (statsType == nullptr) {
const bool largerIsBetter = true;
- StatisticDescriptor** statDescArr = new StatisticDescriptor*[24];
+ std::vector<std::shared_ptr<StatisticDescriptor>> statDescArr(24);
statDescArr[0] = factory->createIntCounter(
"creates", "The total number of cache creates", "entries",
@@ -139,7 +139,7 @@ class APACHE_GEODE_EXPORT CachePerfStats {
statsType = factory->createType("CachePerfStats",
"Statistics about native client cache",
- statDescArr, 24);
+ std::move(statDescArr));
}
// Create Statistics object
m_cachePerfStats =
@@ -206,15 +206,7 @@ class APACHE_GEODE_EXPORT CachePerfStats {
virtual ~CachePerfStats() { m_cachePerfStats = nullptr; }
- void close() {
- /*StatisticDescriptor** statDescArr =
- m_cachePerfStats->getType()->getStatistics();
- for ( int i = 0; i < m_cachePerfStats->getType()->getDescriptorsCount();
- i++) {
- delete statDescArr[i];
- }*/
- m_cachePerfStats->close();
- }
+ void close() { m_cachePerfStats->close(); }
inline void incDestroys() { m_cachePerfStats->incInt(m_destroysId, 1); }
diff --git a/cppcache/src/CqQueryVsdStats.cpp b/cppcache/src/CqQueryVsdStats.cpp
index a93e849..5b2924d 100644
--- a/cppcache/src/CqQueryVsdStats.cpp
+++ b/cppcache/src/CqQueryVsdStats.cpp
@@ -44,7 +44,7 @@ CqQueryVsdStats::CqQueryVsdStats(StatisticsFactory* factory,
auto statsType = factory->findType(STATS_NAME);
if (!statsType) {
const bool largerIsBetter = true;
- auto stats = new StatisticDescriptor*[4];
+ std::vector<std::shared_ptr<StatisticDescriptor>> stats(4);
stats[0] = factory->createIntCounter(
"inserts", "The total number of inserts this cq qurey", "entries",
largerIsBetter);
@@ -58,7 +58,7 @@ CqQueryVsdStats::CqQueryVsdStats(StatisticsFactory* factory,
"events", "The total number of events for this cq query", "entries",
largerIsBetter);
- statsType = factory->createType(STATS_NAME, STATS_DESC, stats, 4);
+ statsType = factory->createType(STATS_NAME, STATS_DESC, std::move(stats));
}
m_cqQueryVsdStats =
diff --git a/cppcache/src/CqServiceVsdStats.cpp
b/cppcache/src/CqServiceVsdStats.cpp
index 85d0102..e520eb2 100644
--- a/cppcache/src/CqServiceVsdStats.cpp
+++ b/cppcache/src/CqServiceVsdStats.cpp
@@ -42,7 +42,7 @@ CqServiceVsdStats::CqServiceVsdStats(StatisticsFactory*
factory,
auto statsType = factory->findType(STATS_NAME);
if (!statsType) {
const bool largerIsBetter = true;
- auto stats = new StatisticDescriptor*[5];
+ std::vector<std::shared_ptr<StatisticDescriptor>> stats(5);
stats[0] = factory->createIntCounter(
"CqsActive", "The total number of CqsActive this cq qurey", "entries",
largerIsBetter);
@@ -60,7 +60,7 @@ CqServiceVsdStats::CqServiceVsdStats(StatisticsFactory*
factory,
"The total number of Cqs on the client for this cq Service", "entries",
largerIsBetter);
- statsType = factory->createType(STATS_NAME, STATS_DESC, stats, 5);
+ statsType = factory->createType(STATS_NAME, STATS_DESC, std::move(stats));
}
m_cqServiceVsdStats =
diff --git a/cppcache/src/ExecutionImpl.cpp b/cppcache/src/ExecutionImpl.cpp
index 4dcb20e..8d65ee7 100644
--- a/cppcache/src/ExecutionImpl.cpp
+++ b/cppcache/src/ExecutionImpl.cpp
@@ -73,7 +73,7 @@ Execution
ExecutionImpl::withCollector(std::shared_ptr<ResultCollector> rs) {
m_authenticatedView)));
}
-std::vector<int8_t>* ExecutionImpl::getFunctionAttributes(
+std::shared_ptr<std::vector<int8_t>> ExecutionImpl::getFunctionAttributes(
const std::string& func) {
auto&& itr = m_func_attrs.find(func);
if (itr != m_func_attrs.end()) {
@@ -360,8 +360,8 @@ std::shared_ptr<ResultCollector> ExecutionImpl::execute(
return m_rc;
}
-GfErrType ExecutionImpl::getFuncAttributes(const std::string& func,
- std::vector<int8_t>** attr) {
+GfErrType ExecutionImpl::getFuncAttributes(
+ const std::string& func, std::shared_ptr<std::vector<int8_t>>* attr) {
ThinClientPoolDM* tcrdm = dynamic_cast<ThinClientPoolDM*>(m_pool.get());
if (tcrdm == nullptr) {
throw IllegalArgumentException(
diff --git a/cppcache/src/ExecutionImpl.hpp b/cppcache/src/ExecutionImpl.hpp
index f7b89ac..0a6be4c 100644
--- a/cppcache/src/ExecutionImpl.hpp
+++ b/cppcache/src/ExecutionImpl.hpp
@@ -35,7 +35,7 @@ namespace apache {
namespace geode {
namespace client {
-typedef std::map<std::string, std::vector<int8_t>*>
+typedef std::map<std::string, std::shared_ptr<std::vector<int8_t>>>
FunctionToFunctionAttributes;
class ExecutionImpl {
@@ -119,9 +119,10 @@ class ExecutionImpl {
const std::string& func, uint8_t getResult,
std::chrono::milliseconds timeout = DEFAULT_QUERY_RESPONSE_TIMEOUT);
- std::vector<int8_t>* getFunctionAttributes(const std::string& func);
+ std::shared_ptr<std::vector<int8_t>> getFunctionAttributes(
+ const std::string& func);
GfErrType getFuncAttributes(const std::string& func,
- std::vector<int8_t>** attr);
+ std::shared_ptr<std::vector<int8_t>>* attr);
};
} // namespace client
} // namespace geode
diff --git a/cppcache/src/ExpiryTaskManager.cpp
b/cppcache/src/ExpiryTaskManager.cpp
index d7b90d5..bc922de 100644
--- a/cppcache/src/ExpiryTaskManager.cpp
+++ b/cppcache/src/ExpiryTaskManager.cpp
@@ -38,16 +38,14 @@ namespace client {
const char* ExpiryTaskManager::NC_ETM_Thread = "NC ETM Thread";
ExpiryTaskManager::ExpiryTaskManager() : m_reactorEventLoopRunning(false) {
- auto timer = std::unique_ptr<GF_Timer_Heap_ImmediateReset>(
- new GF_Timer_Heap_ImmediateReset());
+ auto timer = new GF_Timer_Heap_ImmediateReset();
#if defined(_WIN32)
- m_reactor = new ACE_Reactor(new ACE_WFMO_Reactor(nullptr, timer.get()), 1);
+ m_reactor = new ACE_Reactor(new ACE_WFMO_Reactor(nullptr, timer), 1);
#elif defined(WITH_ACE_Select_Reactor)
- m_reactor = new ACE_Reactor(new ACE_Select_Reactor(nullptr, timer.get()), 1);
+ m_reactor = new ACE_Reactor(new ACE_Select_Reactor(nullptr, timer), 1);
#else
- m_reactor = new ACE_Reactor(new ACE_Dev_Poll_Reactor(nullptr, timer.get())
1);
+ m_reactor = new ACE_Reactor(new ACE_Dev_Poll_Reactor(nullptr, timer) 1);
#endif
- timer.release();
}
int ExpiryTaskManager::resetTask(ExpiryTaskManager::id_type id, uint32_t sec) {
@@ -92,6 +90,7 @@ void ExpiryTaskManager::begin() {
ExpiryTaskManager::~ExpiryTaskManager() {
stopExpiryTaskManager();
+
delete m_reactor;
m_reactor = nullptr;
}
diff --git a/cppcache/src/PoolStatistics.cpp b/cppcache/src/PoolStatistics.cpp
index 23a2324..098c959 100644
--- a/cppcache/src/PoolStatistics.cpp
+++ b/cppcache/src/PoolStatistics.cpp
@@ -43,7 +43,7 @@ PoolStats::PoolStats(StatisticsFactory* factory, const
std::string& poolName) {
auto statsType = factory->findType(STATS_NAME);
if (statsType == nullptr) {
- auto stats = new StatisticDescriptor*[27];
+ std::vector<std::shared_ptr<StatisticDescriptor>> stats(27);
stats[0] = factory->createIntGauge(
"locators", "Current number of locators discovered", "locators");
@@ -133,7 +133,7 @@ PoolStats::PoolStats(StatisticsFactory* factory, const
std::string& poolName) {
"queryExecutionTime",
"Total time spent while processing queryExecution", "nanoseconds");
- statsType = factory->createType(STATS_NAME, STATS_DESC, stats, 27);
+ statsType = factory->createType(STATS_NAME, STATS_DESC, std::move(stats));
}
m_locatorsId = statsType->nameToId("locators");
m_serversId = statsType->nameToId("servers");
diff --git a/cppcache/src/RegionStats.cpp b/cppcache/src/RegionStats.cpp
index aa7feea..1a9c98e 100644
--- a/cppcache/src/RegionStats.cpp
+++ b/cppcache/src/RegionStats.cpp
@@ -40,7 +40,7 @@ RegionStats::RegionStats(StatisticsFactory* factory,
if (!statsType) {
const bool largerIsBetter = true;
- auto stats = new StatisticDescriptor*[25];
+ std::vector<std::shared_ptr<StatisticDescriptor>> stats(25);
stats[0] = factory->createIntCounter(
"creates", "The total number of cache creates for this region",
"entries", largerIsBetter);
@@ -135,7 +135,7 @@ RegionStats::RegionStats(StatisticsFactory* factory,
"removeAllTime",
"Total time spent doing removeAlls operations for this region",
"Nanoseconds", !largerIsBetter);
- statsType = factory->createType(STATS_NAME, STATS_DESC, stats, 25);
+ statsType = factory->createType(STATS_NAME, STATS_DESC, std::move(stats));
}
m_destroysId = statsType->nameToId("destroys");
diff --git a/cppcache/src/TcrConnection.cpp b/cppcache/src/TcrConnection.cpp
index b4ea2ca..2e18dc6 100644
--- a/cppcache/src/TcrConnection.cpp
+++ b/cppcache/src/TcrConnection.cpp
@@ -1112,29 +1112,25 @@ std::vector<int8_t> TcrConnection::readHandshakeData(
if (msgLength < 0) {
msgLength = 0;
}
- char* recvMessage;
- _GEODE_NEW(recvMessage, char[msgLength + 1]);
- recvMessage[msgLength] = '\0';
+ std::vector<int8_t> message(msgLength + 1);
+ message.data()[msgLength] = '\0';
if (msgLength == 0) {
- return std::vector<int8_t>(recvMessage, recvMessage + 1);
+ return message;
}
- if ((error = receiveData(recvMessage, msgLength, connectTimeout, false)) !=
- CONN_NOERR) {
+ if ((error = receiveData(reinterpret_cast<char*>(message.data()), msgLength,
+ connectTimeout, false)) != CONN_NOERR) {
+ GF_SAFE_DELETE_CON(m_conn);
if (error & CONN_TIMEOUT) {
- _GEODE_SAFE_DELETE_ARRAY(recvMessage);
- GF_SAFE_DELETE_CON(m_conn);
throwException(
TimeoutException("TcrConnection::TcrConnection: "
"Timeout in handshake"));
} else {
- _GEODE_SAFE_DELETE_ARRAY(recvMessage);
- GF_SAFE_DELETE_CON(m_conn);
throwException(
GeodeIOException("TcrConnection::TcrConnection: "
"Handshake failure"));
}
} else {
- return std::vector<int8_t>(recvMessage, recvMessage + msgLength + 1);
+ return message;
}
}
@@ -1147,26 +1143,21 @@ std::shared_ptr<CacheableBytes>
TcrConnection::readHandshakeRawData(
if (msgLength == 0) {
return nullptr;
}
- char* recvMessage;
- _GEODE_NEW(recvMessage, char[msgLength]);
- if ((error = receiveData(recvMessage, msgLength, connectTimeout, false)) !=
- CONN_NOERR) {
+ std::vector<int8_t> message(msgLength);
+ if ((error = receiveData(reinterpret_cast<char*>(message.data()), msgLength,
+ connectTimeout, false)) != CONN_NOERR) {
+ GF_SAFE_DELETE_CON(m_conn);
if (error & CONN_TIMEOUT) {
- _GEODE_SAFE_DELETE_ARRAY(recvMessage);
- GF_SAFE_DELETE_CON(m_conn);
throwException(
TimeoutException("TcrConnection::TcrConnection: "
"Timeout in handshake"));
} else {
- _GEODE_SAFE_DELETE_ARRAY(recvMessage);
- GF_SAFE_DELETE_CON(m_conn);
throwException(
GeodeIOException("TcrConnection::TcrConnection: "
"Handshake failure"));
}
} else {
- return CacheableBytes::create(
- std::vector<int8_t>(recvMessage, recvMessage + msgLength));
+ return CacheableBytes::create(std::move(message));
}
}
diff --git a/cppcache/src/TcrConnectionManager.cpp
b/cppcache/src/TcrConnectionManager.cpp
index 0643f47..da338d4 100644
--- a/cppcache/src/TcrConnectionManager.cpp
+++ b/cppcache/src/TcrConnectionManager.cpp
@@ -67,7 +67,8 @@ TcrConnectionManager::TcrConnectionManager(CacheImpl *cache)
m_redundancyTask(nullptr),
m_isDurable(false),
m_isNetDown(false) {
- m_redundancyManager = new ThinClientRedundancyManager(this);
+ m_redundancyManager = std::unique_ptr<ThinClientRedundancyManager>(
+ new ThinClientRedundancyManager(this));
}
ExpiryTaskManager::id_type TcrConnectionManager::getPingTaskId() {
diff --git a/cppcache/src/TcrConnectionManager.hpp
b/cppcache/src/TcrConnectionManager.hpp
index 837e448..27ffa7d 100644
--- a/cppcache/src/TcrConnectionManager.hpp
+++ b/cppcache/src/TcrConnectionManager.hpp
@@ -179,7 +179,7 @@ class TcrConnectionManager {
bool m_isNetDown;
- ThinClientRedundancyManager* m_redundancyManager;
+ std::unique_ptr<ThinClientRedundancyManager> m_redundancyManager;
void failover(std::atomic<bool>& isRunning);
void redundancy(std::atomic<bool>& isRunning);
diff --git a/cppcache/src/TcrMessage.cpp b/cppcache/src/TcrMessage.cpp
index e05e12f..7282393 100644
--- a/cppcache/src/TcrMessage.cpp
+++ b/cppcache/src/TcrMessage.cpp
@@ -239,7 +239,7 @@ int8_t TcrMessage::getserverGroupVersion() const {
return m_serverGroupVersion;
}
-std::vector<int8_t>* TcrMessage::getFunctionAttributes() {
+std::shared_ptr<std::vector<int8_t>> TcrMessage::getFunctionAttributes() {
return m_functionAttributes;
}
@@ -1206,7 +1206,9 @@ void TcrMessage::handleByteArrayResponse(
input.readInt32();
input.advanceCursor(1); // ignore byte
- m_functionAttributes = new std::vector<int8_t>();
+ if (!m_functionAttributes) {
+ m_functionAttributes = std::make_shared<std::vector<int8_t>>();
+ }
m_functionAttributes->push_back(input.read());
m_functionAttributes->push_back(input.read());
m_functionAttributes->push_back(input.read());
diff --git a/cppcache/src/TcrMessage.hpp b/cppcache/src/TcrMessage.hpp
index f2d2cd7..89d4870 100644
--- a/cppcache/src/TcrMessage.hpp
+++ b/cppcache/src/TcrMessage.hpp
@@ -275,7 +275,7 @@ class TcrMessage {
int8_t getMetaDataVersion() const;
uint32_t getEntryNotFound() const;
int8_t getserverGroupVersion() const;
- std::vector<int8_t>* getFunctionAttributes();
+ std::shared_ptr<std::vector<int8_t>> getFunctionAttributes();
// set the DM for chunked response messages
void setDM(ThinClientBaseDM* dm);
@@ -420,7 +420,7 @@ class TcrMessage {
std::unique_ptr<DataInput> m_delta;
int8_t* m_deltaBytes;
std::vector<std::shared_ptr<FixedPartitionAttributesImpl>>* m_fpaSet;
- std::vector<int8_t>* m_functionAttributes;
+ std::shared_ptr<std::vector<int8_t>> m_functionAttributes;
std::shared_ptr<CacheableBytes> m_connectionIDBytes;
std::shared_ptr<Properties> m_creds;
std::shared_ptr<CacheableKey> m_key;
diff --git a/cppcache/src/ThinClientPoolDM.cpp
b/cppcache/src/ThinClientPoolDM.cpp
index 67eb9b3..120332e 100644
--- a/cppcache/src/ThinClientPoolDM.cpp
+++ b/cppcache/src/ThinClientPoolDM.cpp
@@ -703,42 +703,35 @@ GfErrType ThinClientPoolDM::sendRequestToAllServers(
const std::shared_ptr<CacheableStringArray> ThinClientPoolDM::getLocators()
const {
- auto ptrArr =
- new std::shared_ptr<CacheableString>[m_attrs->m_initLocList.size()];
- int32_t i = 0;
+ std::vector<std::shared_ptr<CacheableString>> locators;
+ locators.reserve(m_attrs->m_initLocList.size());
for (auto&& locator : m_attrs->m_initLocList) {
- ptrArr[i++] = CacheableString::create(locator);
+ locators.emplace_back(CacheableString::create(locator));
}
- return CacheableStringArray::create(
- std::vector<std::shared_ptr<CacheableString>>(ptrArr, ptrArr + i));
+ return CacheableStringArray::create(std::move(locators));
}
const std::shared_ptr<CacheableStringArray> ThinClientPoolDM::getServers() {
+ std::vector<std::shared_ptr<CacheableString>> servers;
if (!m_attrs->m_initServList.empty()) {
- auto ptrArr =
- new std::shared_ptr<CacheableString>[m_attrs->m_initServList.size()];
- int32_t i = 0;
+ servers.reserve(m_attrs->m_initServList.size());
+
for (auto&& server : m_attrs->m_initServList) {
- ptrArr[i++] = CacheableString::create(server);
+ servers.emplace_back(CacheableString::create(server));
}
- return CacheableStringArray::create(
- std::vector<std::shared_ptr<CacheableString>>(ptrArr, ptrArr + i));
+ return CacheableStringArray::create(std::move(servers));
} else if (!m_attrs->m_initLocList.empty()) {
std::vector<std::shared_ptr<ServerLocation>> vec;
m_locHelper->getAllServers(vec, m_attrs->m_serverGrp);
- auto ptrArr = new std::shared_ptr<CacheableString>[vec.size()];
- int32_t i = 0;
+ servers.reserve(vec.size());
for (auto&& serLoc : vec) {
- ptrArr[i++] = CacheableString::create(serLoc->getServerName() + ":" +
- std::to_string(serLoc->getPort()));
+ servers.emplace_back(CacheableString::create(
+ serLoc->getServerName() + ":" + std::to_string(serLoc->getPort())));
}
- return CacheableStringArray::create(
- std::vector<std::shared_ptr<CacheableString>>(ptrArr, ptrArr + i));
- } else {
- return CacheableStringArray::create(
- std::vector<std::shared_ptr<CacheableString>>{});
+ return CacheableStringArray::create(std::move(servers));
}
+ return CacheableStringArray::create(std::move(servers));
}
void ThinClientPoolDM::stopPingThread() {
diff --git a/cppcache/src/ThinClientRegion.cpp
b/cppcache/src/ThinClientRegion.cpp
index be95f76..6143c8c 100644
--- a/cppcache/src/ThinClientRegion.cpp
+++ b/cppcache/src/ThinClientRegion.cpp
@@ -994,7 +994,8 @@ GfErrType ThinClientRegion::putNoThrow_remote(
TcrMessagePut request(new DataOutput(m_cacheImpl->createDataOutput()), this,
keyPtr, valuePtr, aCallbackArgument, delta,
m_tcrdm.get());
- TcrMessageReply* reply = new TcrMessageReply(true, m_tcrdm.get());
+ auto reply = std::unique_ptr<TcrMessageReply>(
+ new TcrMessageReply(true, m_tcrdm.get()));
err = m_tcrdm->sendSyncRequest(request, *reply);
if (delta) {
// Does not check whether success of failure..
@@ -1004,8 +1005,8 @@ GfErrType ThinClientRegion::putNoThrow_remote(
TcrMessagePut request(new DataOutput(m_cacheImpl->createDataOutput()),
this, keyPtr, valuePtr, aCallbackArgument, false,
m_tcrdm.get(), false, true);
- delete reply;
- reply = new TcrMessageReply(true, m_tcrdm.get());
+ reply = std::unique_ptr<TcrMessageReply>(
+ new TcrMessageReply(true, m_tcrdm.get()));
err = m_tcrdm->sendSyncRequest(request, *reply);
}
}
@@ -1031,8 +1032,6 @@ GfErrType ThinClientRegion::putNoThrow_remote(
err = GF_MSG;
}
}
- delete reply;
- reply = nullptr;
return err;
}
@@ -3226,8 +3225,8 @@ bool ThinClientRegion::executeFunctionSH(
return reExecute;
}
-GfErrType ThinClientRegion::getFuncAttributes(const std::string& func,
- std::vector<int8_t>** attr) {
+GfErrType ThinClientRegion::getFuncAttributes(
+ const std::string& func, std::shared_ptr<std::vector<int8_t>>* attr) {
GfErrType err = GF_NOERR;
// do TCR GET_FUNCTION_ATTRIBUTES
diff --git a/cppcache/src/ThinClientRegion.hpp
b/cppcache/src/ThinClientRegion.hpp
index 1da5bce..8e82adc 100644
--- a/cppcache/src/ThinClientRegion.hpp
+++ b/cppcache/src/ThinClientRegion.hpp
@@ -171,7 +171,7 @@ class APACHE_GEODE_EXPORT ThinClientRegion : public
LocalRegion {
std::chrono::milliseconds timeout = DEFAULT_QUERY_RESPONSE_TIMEOUT);
GfErrType getFuncAttributes(const std::string& func,
- std::vector<int8_t>** attr);
+ std::shared_ptr<std::vector<int8_t>>* attr);
ACE_RW_Thread_Mutex& getMataDataMutex() { return m_RegionMutex; }
diff --git a/cppcache/src/statistics/AtomicStatisticsImpl.cpp
b/cppcache/src/statistics/AtomicStatisticsImpl.cpp
index 407e436..7348178 100644
--- a/cppcache/src/statistics/AtomicStatisticsImpl.cpp
+++ b/cppcache/src/statistics/AtomicStatisticsImpl.cpp
@@ -206,8 +206,9 @@ double AtomicStatisticsImpl::_getDouble(int32_t offset)
const {
}
int64_t AtomicStatisticsImpl::_getRawBits(
- const StatisticDescriptor* statDscp) const {
- const auto stat = dynamic_cast<const StatisticDescriptorImpl*>(statDscp);
+ const std::shared_ptr<StatisticDescriptor> statDscp) const {
+ const auto stat =
+ std::dynamic_pointer_cast<StatisticDescriptorImpl>(statDscp);
switch (stat->getTypeCode()) {
case INT_TYPE:
return getInt(stat->getId());
@@ -228,7 +229,7 @@ int64_t AtomicStatisticsImpl::_getRawBits(
}
int64_t AtomicStatisticsImpl::getRawBits(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
if (isOpen()) {
return _getRawBits(descriptor);
} else {
@@ -278,7 +279,7 @@ int32_t AtomicStatisticsImpl::nameToId(const std::string&
name) const {
return statsType->nameToId(name);
}
-StatisticDescriptor* AtomicStatisticsImpl::nameToDescriptor(
+std::shared_ptr<StatisticDescriptor> AtomicStatisticsImpl::nameToDescriptor(
const std::string& name) const {
return statsType->nameToDescriptor(name);
}
@@ -300,8 +301,8 @@ void AtomicStatisticsImpl::setInt(const std::string& name,
int32_t value) {
setInt(id, value);
}
-void AtomicStatisticsImpl::setInt(const StatisticDescriptor* descriptor,
- int32_t value) {
+void AtomicStatisticsImpl::setInt(
+ const std::shared_ptr<StatisticDescriptor> descriptor, int32_t value) {
int32_t id = getIntId(descriptor);
setInt(id, value);
}
@@ -316,8 +317,8 @@ void AtomicStatisticsImpl::setLong(const std::string& name,
int64_t value) {
setLong(nameToDescriptor(name), value);
}
-void AtomicStatisticsImpl::setLong(const StatisticDescriptor* descriptor,
- int64_t value) {
+void AtomicStatisticsImpl::setLong(
+ const std::shared_ptr<StatisticDescriptor> descriptor, int64_t value) {
setLong(getLongId(descriptor), value);
}
@@ -331,8 +332,8 @@ void AtomicStatisticsImpl::setDouble(const std::string&
name, double value) {
setDouble(nameToDescriptor(name), value);
}
-void AtomicStatisticsImpl::setDouble(const StatisticDescriptor* descriptor,
- double value) {
+void AtomicStatisticsImpl::setDouble(
+ const std::shared_ptr<StatisticDescriptor> descriptor, double value) {
setDouble(getDoubleId(descriptor), value);
}
@@ -348,7 +349,7 @@ int32_t AtomicStatisticsImpl::getInt(const std::string&
name) const {
}
int32_t AtomicStatisticsImpl::getInt(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
int32_t id = getIntId(descriptor);
return getInt(id);
}
@@ -366,7 +367,7 @@ int64_t AtomicStatisticsImpl::getLong(const std::string&
name) const {
}
int64_t AtomicStatisticsImpl::getLong(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
return getLong(getLongId(descriptor));
}
@@ -383,7 +384,7 @@ double AtomicStatisticsImpl::getDouble(const std::string&
name) const {
}
double AtomicStatisticsImpl::getDouble(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
return getDouble(getDoubleId(descriptor));
}
@@ -400,8 +401,8 @@ int32_t AtomicStatisticsImpl::incInt(const std::string&
name, int32_t delta) {
return incInt(id, delta);
}
-int32_t AtomicStatisticsImpl::incInt(const StatisticDescriptor* descriptor,
- int32_t delta) {
+int32_t AtomicStatisticsImpl::incInt(
+ const std::shared_ptr<StatisticDescriptor> descriptor, int32_t delta) {
int32_t id = getIntId(descriptor);
return incInt(id, delta);
}
@@ -418,8 +419,8 @@ int64_t AtomicStatisticsImpl::incLong(const std::string&
name, int64_t delta) {
return incLong(nameToDescriptor(name), delta);
}
-int64_t AtomicStatisticsImpl::incLong(const StatisticDescriptor* descriptor,
- int64_t delta) {
+int64_t AtomicStatisticsImpl::incLong(
+ const std::shared_ptr<StatisticDescriptor> descriptor, int64_t delta) {
return incLong(getLongId(descriptor), delta);
}
@@ -435,8 +436,8 @@ double AtomicStatisticsImpl::incDouble(const std::string&
name, double delta) {
return incDouble(nameToDescriptor(name), delta);
}
-double AtomicStatisticsImpl::incDouble(const StatisticDescriptor* descriptor,
- double delta) {
+double AtomicStatisticsImpl::incDouble(
+ const std::shared_ptr<StatisticDescriptor> descriptor, double delta) {
return incDouble(getDoubleId(descriptor), delta);
}
@@ -449,23 +450,23 @@ double AtomicStatisticsImpl::incDouble(int32_t id, double
delta) {
}
int32_t AtomicStatisticsImpl::getIntId(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
const auto realDescriptor =
- dynamic_cast<const StatisticDescriptorImpl*>(descriptor);
+ std::dynamic_pointer_cast<StatisticDescriptorImpl>(descriptor);
return realDescriptor->checkInt();
}
int32_t AtomicStatisticsImpl::getLongId(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
const auto realDescriptor =
- dynamic_cast<const StatisticDescriptorImpl*>(descriptor);
+ std::dynamic_pointer_cast<StatisticDescriptorImpl>(descriptor);
return realDescriptor->checkLong();
}
int32_t AtomicStatisticsImpl::getDoubleId(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
const auto realDescriptor =
- dynamic_cast<const StatisticDescriptorImpl*>(descriptor);
+ std::dynamic_pointer_cast<StatisticDescriptorImpl>(descriptor);
return realDescriptor->checkDouble();
}
diff --git a/cppcache/src/statistics/AtomicStatisticsImpl.hpp
b/cppcache/src/statistics/AtomicStatisticsImpl.hpp
index baad1e7..a824845 100644
--- a/cppcache/src/statistics/AtomicStatisticsImpl.hpp
+++ b/cppcache/src/statistics/AtomicStatisticsImpl.hpp
@@ -73,11 +73,13 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
///////////////////////Private Methods//////////////////////////
bool isOpen() const;
- int32_t getIntId(const StatisticDescriptor* descriptor) const;
+ int32_t getIntId(const std::shared_ptr<StatisticDescriptor> descriptor)
const;
- int32_t getLongId(const StatisticDescriptor* descriptor) const;
+ int32_t getLongId(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const;
- int32_t getDoubleId(const StatisticDescriptor* descriptor) const;
+ int32_t getDoubleId(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const;
////////////////////// Static private Methods //////////////////////
@@ -116,7 +118,8 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
int32_t nameToId(const std::string& name) const override;
- StatisticDescriptor* nameToDescriptor(const std::string& name) const
override;
+ std::shared_ptr<StatisticDescriptor> nameToDescriptor(
+ const std::string& name) const override;
bool isClosed() const override;
@@ -139,19 +142,22 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
void setInt(const std::string& name, int32_t value) override;
- void setInt(const StatisticDescriptor* descriptor, int32_t value) override;
+ void setInt(const std::shared_ptr<StatisticDescriptor> descriptor,
+ int32_t value) override;
void setInt(int32_t offset, int32_t value) override;
void setLong(const std::string& name, int64_t value) override;
- void setLong(const StatisticDescriptor* descriptor, int64_t value) override;
+ void setLong(const std::shared_ptr<StatisticDescriptor> descriptor,
+ int64_t value) override;
void setLong(int32_t id, int64_t value) override;
void setDouble(const std::string& name, double value) override;
- void setDouble(const StatisticDescriptor* descriptor, double value) override;
+ void setDouble(const std::shared_ptr<StatisticDescriptor> descriptor,
+ double value) override;
void setDouble(int32_t id, double value) override;
@@ -159,42 +165,47 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
int32_t getInt(const std::string& name) const override;
- int32_t getInt(const StatisticDescriptor* descriptor) const override;
+ int32_t getInt(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const override;
int32_t getInt(int32_t offset) const override;
int64_t getLong(const std::string& name) const override;
- int64_t getLong(const StatisticDescriptor* descriptor) const override;
+ int64_t getLong(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const override;
int64_t getLong(int32_t id) const override;
double getDouble(const std::string& name) const override;
- double getDouble(const StatisticDescriptor* descriptor) const override;
+ double getDouble(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const override;
double getDouble(int32_t id) const override;
- int64_t getRawBits(const StatisticDescriptor* descriptor) const override;
+ int64_t getRawBits(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const override;
//////////////////////// inc() Methods ////////////////////////
int32_t incInt(const std::string& name, int32_t delta) override;
- int32_t incInt(const StatisticDescriptor* descriptor, int32_t delta)
override;
+ int32_t incInt(const std::shared_ptr<StatisticDescriptor> descriptor,
+ int32_t delta) override;
int32_t incInt(int32_t offset, int32_t delta) override;
int64_t incLong(const std::string& name, int64_t delta) override;
- int64_t incLong(const StatisticDescriptor* descriptor,
+ int64_t incLong(const std::shared_ptr<StatisticDescriptor> descriptor,
int64_t delta) override;
int64_t incLong(int32_t id, int64_t delta) override;
double incDouble(const std::string& name, double delta) override;
- double incDouble(const StatisticDescriptor* descriptor,
+ double incDouble(const std::shared_ptr<StatisticDescriptor> descriptor,
double delta) override;
double incDouble(int32_t id, double delta) override;
@@ -216,7 +227,7 @@ class AtomicStatisticsImpl : public Statistics, private
client::NonCopyable {
* Returns the bits that represent the raw value of the
* specified statistic descriptor.
*/
- int64_t _getRawBits(const StatisticDescriptor* stat) const;
+ int64_t _getRawBits(const std::shared_ptr<StatisticDescriptor> stat) const;
int32_t _incInt(int32_t offset, int32_t delta);
diff --git a/cppcache/src/statistics/GeodeStatisticsFactory.cpp
b/cppcache/src/statistics/GeodeStatisticsFactory.cpp
index 834d61d..8ea2809 100644
--- a/cppcache/src/statistics/GeodeStatisticsFactory.cpp
+++ b/cppcache/src/statistics/GeodeStatisticsFactory.cpp
@@ -171,8 +171,8 @@ StatisticsTypeImpl*
GeodeStatisticsFactory::addType(StatisticsTypeImpl* st) {
*/
StatisticsType* GeodeStatisticsFactory::createType(
const std::string& name, const std::string& description,
- StatisticDescriptor** stats, int32_t statsLength) {
- auto st = new StatisticsTypeImpl(name, description, stats, statsLength);
+ std::vector<std::shared_ptr<StatisticDescriptor>> stats) {
+ auto st = new StatisticsTypeImpl(name, description, std::move(stats));
if (st != nullptr) {
st = addType(st);
@@ -195,42 +195,44 @@ StatisticsType* GeodeStatisticsFactory::findType(
}
}
-StatisticDescriptor* GeodeStatisticsFactory::createIntCounter(
+std::shared_ptr<StatisticDescriptor> GeodeStatisticsFactory::createIntCounter(
const std::string& name, const std::string& description,
const std::string& units, bool largerBetter) {
return StatisticDescriptorImpl::createIntCounter(name, description, units,
largerBetter);
}
-StatisticDescriptor* GeodeStatisticsFactory::createLongCounter(
+std::shared_ptr<StatisticDescriptor> GeodeStatisticsFactory::createLongCounter(
const std::string& name, const std::string& description,
const std::string& units, bool largerBetter) {
return StatisticDescriptorImpl::createLongCounter(name, description, units,
largerBetter);
}
-StatisticDescriptor* GeodeStatisticsFactory::createDoubleCounter(
- const std::string& name, const std::string& description,
- const std::string& units, bool largerBetter) {
+std::shared_ptr<StatisticDescriptor>
+GeodeStatisticsFactory::createDoubleCounter(const std::string& name,
+ const std::string& description,
+ const std::string& units,
+ bool largerBetter) {
return StatisticDescriptorImpl::createDoubleCounter(name, description, units,
largerBetter);
}
-StatisticDescriptor* GeodeStatisticsFactory::createIntGauge(
+std::shared_ptr<StatisticDescriptor> GeodeStatisticsFactory::createIntGauge(
const std::string& name, const std::string& description,
const std::string& units, bool largerBetter) {
return StatisticDescriptorImpl::createIntGauge(name, description, units,
largerBetter);
}
-StatisticDescriptor* GeodeStatisticsFactory::createLongGauge(
+std::shared_ptr<StatisticDescriptor> GeodeStatisticsFactory::createLongGauge(
const std::string& name, const std::string& description,
const std::string& units, bool largerBetter) {
return StatisticDescriptorImpl::createLongGauge(name, description, units,
largerBetter);
}
-StatisticDescriptor* GeodeStatisticsFactory::createDoubleGauge(
+std::shared_ptr<StatisticDescriptor> GeodeStatisticsFactory::createDoubleGauge(
const std::string& name, const std::string& description,
const std::string& units, bool largerBetter) {
return StatisticDescriptorImpl::createDoubleGauge(name, description, units,
diff --git a/cppcache/src/statistics/GeodeStatisticsFactory.hpp
b/cppcache/src/statistics/GeodeStatisticsFactory.hpp
index 4d6ed46..df4f8b3 100644
--- a/cppcache/src/statistics/GeodeStatisticsFactory.hpp
+++ b/cppcache/src/statistics/GeodeStatisticsFactory.hpp
@@ -94,42 +94,35 @@ class GeodeStatisticsFactory : public StatisticsFactory {
const std::string& textId,
int64_t numericId) override;
- StatisticsType* createType(const std::string& name,
- const std::string& description,
- StatisticDescriptor** stats,
- int32_t statsLength) override;
+ StatisticsType* createType(
+ const std::string& name, const std::string& description,
+ std::vector<std::shared_ptr<StatisticDescriptor>> stats) override;
StatisticsType* findType(const std::string& name) const override;
- StatisticDescriptor* createIntCounter(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool largerBetter) override;
-
- StatisticDescriptor* createLongCounter(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool largerBetter) override;
-
- StatisticDescriptor* createDoubleCounter(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool largerBetter) override;
-
- StatisticDescriptor* createIntGauge(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool largerBetter) override;
-
- StatisticDescriptor* createLongGauge(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool largerBetter) override;
-
- StatisticDescriptor* createDoubleGauge(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool largerBetter) override;
+ std::shared_ptr<StatisticDescriptor> createIntCounter(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter) override;
+
+ std::shared_ptr<StatisticDescriptor> createLongCounter(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter) override;
+
+ std::shared_ptr<StatisticDescriptor> createDoubleCounter(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter) override;
+
+ std::shared_ptr<StatisticDescriptor> createIntGauge(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter) override;
+
+ std::shared_ptr<StatisticDescriptor> createLongGauge(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter) override;
+
+ std::shared_ptr<StatisticDescriptor> createDoubleGauge(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter) override;
Statistics* findFirstStatisticsByType(
const StatisticsType* type) const override;
diff --git a/cppcache/src/statistics/OsStatisticsImpl.cpp
b/cppcache/src/statistics/OsStatisticsImpl.cpp
index 2afbc22..2188e3b 100644
--- a/cppcache/src/statistics/OsStatisticsImpl.cpp
+++ b/cppcache/src/statistics/OsStatisticsImpl.cpp
@@ -234,10 +234,9 @@ double OsStatisticsImpl::_getDouble(int32_t offset) const {
}
int64_t OsStatisticsImpl::_getRawBits(
- const StatisticDescriptor* statDscp) const {
- const auto stat = dynamic_cast<const StatisticDescriptorImpl*>(statDscp);
- // dynamic cast is giving problems , so a normal cast was used
- // StatisticDescriptorImpl* stat = (StatisticDescriptorImpl*)statDscp;
+ const std::shared_ptr<StatisticDescriptor> statDscp) const {
+ const std::shared_ptr<StatisticDescriptorImpl> stat =
+ std::dynamic_pointer_cast<StatisticDescriptorImpl>(statDscp);
switch (stat->getTypeCode()) {
case INT_TYPE:
return _getInt(stat->getId());
@@ -302,7 +301,7 @@ int32_t OsStatisticsImpl::nameToId(const std::string& name)
const {
return statsType->nameToId(name);
}
-StatisticDescriptor* OsStatisticsImpl::nameToDescriptor(
+std::shared_ptr<StatisticDescriptor> OsStatisticsImpl::nameToDescriptor(
const std::string& name) const {
return statsType->nameToDescriptor(name);
}
@@ -329,8 +328,8 @@ void OsStatisticsImpl::setInt(const std::string& name,
int32_t value) {
setInt(nameToDescriptor(name), value);
}
-void OsStatisticsImpl::setInt(const StatisticDescriptor* descriptor,
- int32_t value) {
+void OsStatisticsImpl::setInt(
+ const std::shared_ptr<StatisticDescriptor> descriptor, int32_t value) {
setInt(getIntId(descriptor), value);
}
@@ -345,8 +344,8 @@ void OsStatisticsImpl::setLong(const std::string& name,
int64_t value) {
setLong(nameToDescriptor(name), value);
}
-void OsStatisticsImpl::setLong(const StatisticDescriptor* descriptor,
- int64_t value) {
+void OsStatisticsImpl::setLong(
+ const std::shared_ptr<StatisticDescriptor> descriptor, int64_t value) {
setLong(getLongId(descriptor), value);
}
@@ -361,8 +360,8 @@ void OsStatisticsImpl::setDouble(const std::string& name,
double value) {
setDouble(nameToDescriptor(name), value);
}
-void OsStatisticsImpl::setDouble(const StatisticDescriptor* descriptor,
- double value) {
+void OsStatisticsImpl::setDouble(
+ const std::shared_ptr<StatisticDescriptor> descriptor, double value) {
setDouble(getDoubleId(descriptor), value);
}
@@ -376,7 +375,8 @@ int32_t OsStatisticsImpl::getInt(const std::string& name)
const {
return getInt(nameToDescriptor(name));
}
-int32_t OsStatisticsImpl::getInt(const StatisticDescriptor* descriptor) const {
+int32_t OsStatisticsImpl::getInt(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
return getInt(getIntId(descriptor));
}
@@ -396,7 +396,8 @@ int64_t OsStatisticsImpl::getLong(const std::string& name)
const {
return getLong(nameToDescriptor(name));
}
-int64_t OsStatisticsImpl::getLong(const StatisticDescriptor* descriptor) const
{
+int64_t OsStatisticsImpl::getLong(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
return getLong(getLongId(descriptor));
}
@@ -414,7 +415,7 @@ double OsStatisticsImpl::getDouble(const std::string& name)
const {
}
double OsStatisticsImpl::getDouble(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
return getDouble(getDoubleId(descriptor));
}
@@ -429,7 +430,7 @@ double OsStatisticsImpl::getDouble(int32_t id) const {
/// methods////////////////////////////////
int64_t OsStatisticsImpl::getRawBits(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
if (isOpen()) {
return _getRawBits(descriptor);
} else {
@@ -442,8 +443,8 @@ int32_t OsStatisticsImpl::incInt(const std::string& name,
int32_t delta) {
return incInt(nameToDescriptor(name), delta);
}
-int32_t OsStatisticsImpl::incInt(const StatisticDescriptor* descriptor,
- int32_t delta) {
+int32_t OsStatisticsImpl::incInt(
+ const std::shared_ptr<StatisticDescriptor> descriptor, int32_t delta) {
return incInt(getIntId(descriptor), delta);
}
@@ -461,8 +462,8 @@ int64_t OsStatisticsImpl::incLong(const std::string& name,
int64_t delta) {
return incLong(nameToDescriptor(name), delta);
}
-int64_t OsStatisticsImpl::incLong(const StatisticDescriptor* descriptor,
- int64_t delta) {
+int64_t OsStatisticsImpl::incLong(
+ const std::shared_ptr<StatisticDescriptor> descriptor, int64_t delta) {
return incLong(getLongId(descriptor), delta);
}
@@ -479,8 +480,8 @@ double OsStatisticsImpl::incDouble(const std::string& name,
double delta) {
return incDouble(nameToDescriptor(name), delta);
}
-double OsStatisticsImpl::incDouble(const StatisticDescriptor* descriptor,
- double delta) {
+double OsStatisticsImpl::incDouble(
+ const std::shared_ptr<StatisticDescriptor> descriptor, double delta) {
return incDouble(getDoubleId(descriptor), delta);
}
@@ -494,23 +495,23 @@ double OsStatisticsImpl::incDouble(int32_t id, double
delta) {
/////////////////////////// GET ID /////////////////////////////////////////
int32_t OsStatisticsImpl::getIntId(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
const auto realDescriptor =
- dynamic_cast<const StatisticDescriptorImpl*>(descriptor);
+ std::dynamic_pointer_cast<StatisticDescriptorImpl>(descriptor);
return realDescriptor->checkInt();
}
int32_t OsStatisticsImpl::getLongId(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
const auto realDescriptor =
- dynamic_cast<const StatisticDescriptorImpl*>(descriptor);
+ std::dynamic_pointer_cast<StatisticDescriptorImpl>(descriptor);
return realDescriptor->checkLong();
}
int32_t OsStatisticsImpl::getDoubleId(
- const StatisticDescriptor* descriptor) const {
+ const std::shared_ptr<StatisticDescriptor> descriptor) const {
const auto realDescriptor =
- dynamic_cast<const StatisticDescriptorImpl*>(descriptor);
+ std::dynamic_pointer_cast<StatisticDescriptorImpl>(descriptor);
return realDescriptor->checkDouble();
}
diff --git a/cppcache/src/statistics/OsStatisticsImpl.hpp
b/cppcache/src/statistics/OsStatisticsImpl.hpp
index 9bde728..bafc98d 100644
--- a/cppcache/src/statistics/OsStatisticsImpl.hpp
+++ b/cppcache/src/statistics/OsStatisticsImpl.hpp
@@ -69,11 +69,13 @@ class OsStatisticsImpl : public Statistics,
///////////////////////Private Methods//////////////////////////
bool isOpen() const;
- int32_t getIntId(const StatisticDescriptor* descriptor) const;
+ int32_t getIntId(const std::shared_ptr<StatisticDescriptor> descriptor)
const;
- int32_t getLongId(const StatisticDescriptor* descriptor) const;
+ int32_t getLongId(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const;
- int32_t getDoubleId(const StatisticDescriptor* descriptor) const;
+ int32_t getDoubleId(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const;
////////////////////// Static private Methods //////////////////////
@@ -111,7 +113,8 @@ class OsStatisticsImpl : public Statistics,
int32_t nameToId(const std::string& name) const override;
- StatisticDescriptor* nameToDescriptor(const std::string& name) const
override;
+ std::shared_ptr<StatisticDescriptor> nameToDescriptor(
+ const std::string& name) const override;
bool isClosed() const override;
@@ -134,19 +137,22 @@ class OsStatisticsImpl : public Statistics,
void setInt(const std::string& name, int32_t value) override;
- void setInt(const StatisticDescriptor* descriptor, int32_t value) override;
+ void setInt(const std::shared_ptr<StatisticDescriptor> descriptor,
+ int32_t value) override;
void setInt(int32_t id, int32_t value) override;
void setLong(const std::string& name, int64_t value) override;
- void setLong(const StatisticDescriptor* descriptor, int64_t value) override;
+ void setLong(const std::shared_ptr<StatisticDescriptor> descriptor,
+ int64_t value) override;
void setLong(int32_t id, int64_t value) override;
void setDouble(const std::string& name, double value) override;
- void setDouble(const StatisticDescriptor* descriptor, double value) override;
+ void setDouble(const std::shared_ptr<StatisticDescriptor> descriptor,
+ double value) override;
void setDouble(int32_t id, double value) override;
@@ -154,42 +160,47 @@ class OsStatisticsImpl : public Statistics,
int32_t getInt(const std::string& name) const override;
- int32_t getInt(const StatisticDescriptor* descriptor) const override;
+ int32_t getInt(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const override;
int32_t getInt(int32_t id) const override;
int64_t getLong(const std::string& name) const override;
- int64_t getLong(const StatisticDescriptor* descriptor) const override;
+ int64_t getLong(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const override;
int64_t getLong(int32_t id) const override;
double getDouble(const std::string& name) const override;
- double getDouble(const StatisticDescriptor* descriptor) const override;
+ double getDouble(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const override;
double getDouble(int32_t id) const override;
- int64_t getRawBits(const StatisticDescriptor* descriptor) const override;
+ int64_t getRawBits(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const override;
//////////////////////// inc() Methods ////////////////////////
int32_t incInt(const std::string& name, int32_t delta) override;
- int32_t incInt(const StatisticDescriptor* descriptor, int32_t delta)
override;
+ int32_t incInt(const std::shared_ptr<StatisticDescriptor> descriptor,
+ int32_t delta) override;
int32_t incInt(int32_t id, int32_t delta) override;
int64_t incLong(const std::string& name, int64_t delta) override;
- int64_t incLong(const StatisticDescriptor* descriptor,
+ int64_t incLong(const std::shared_ptr<StatisticDescriptor> descriptor,
int64_t delta) override;
int64_t incLong(int32_t id, int64_t delta) override;
double incDouble(const std::string& name, double delta) override;
- double incDouble(const StatisticDescriptor* descriptor,
+ double incDouble(const std::shared_ptr<StatisticDescriptor> descriptor,
double delta) override;
double incDouble(int32_t id, double delta) override;
@@ -220,7 +231,7 @@ class OsStatisticsImpl : public Statistics,
* Returns the bits that represent the raw value of the
* specified statistic descriptor.
*/
- int64_t _getRawBits(const StatisticDescriptor* stat) const;
+ int64_t _getRawBits(const std::shared_ptr<StatisticDescriptor> stat) const;
//////////////////////// inc() Methods ////////////////////////
/**
diff --git a/cppcache/src/statistics/StatArchiveWriter.cpp
b/cppcache/src/statistics/StatArchiveWriter.cpp
index d3362e7..fec732e 100644
--- a/cppcache/src/statistics/StatArchiveWriter.cpp
+++ b/cppcache/src/statistics/StatArchiveWriter.cpp
@@ -155,20 +155,21 @@ void StatDataOutput::openFile(std::string filename,
int64_t size) {
// Constructor and Member functions of ResourceType class
-ResourceType::ResourceType(int32_t idArg, const StatisticsType *typeArg) {
+ResourceType::ResourceType(int32_t idArg, const StatisticsType *typeArg)
+ : type(typeArg) {
this->id = idArg;
- this->stats = typeArg->getStatistics();
- int32_t desc = typeArg->getDescriptorsCount();
- this->numOfDescriptors = desc;
}
int32_t ResourceType::getId() const { return this->id; }
-int32_t ResourceType::getNumOfDescriptors() const {
- return this->numOfDescriptors;
+size_t ResourceType::getNumOfDescriptors() const {
+ return this->type->getDescriptorsCount();
}
-StatisticDescriptor **ResourceType::getStats() const { return this->stats; }
+const std::vector<std::shared_ptr<StatisticDescriptor>>
+ &ResourceType::getStats() const {
+ return this->type->getStatistics();
+}
// Constructor and Member functions of ResourceInst class
@@ -179,10 +180,10 @@ ResourceInst::ResourceInst(int32_t idArg, Statistics
*resourceArg,
id = idArg;
resource = resourceArg;
dataOut = dataOutArg;
- int32_t cnt = type->getNumOfDescriptors();
+ auto cnt = type->getNumOfDescriptors();
archivedStatValues = new int64_t[cnt];
// initialize to zero
- for (int32_t i = 0; i < cnt; i++) {
+ for (decltype(cnt) i = 0; i < cnt; i++) {
archivedStatValues[i] = 0;
}
firstTime = true;
@@ -196,14 +197,14 @@ Statistics *ResourceInst::getResource() { return
this->resource; }
const ResourceType *ResourceInst::getType() const { return this->type; }
-int64_t ResourceInst::getStatValue(StatisticDescriptor *f) {
+int64_t ResourceInst::getStatValue(std::shared_ptr<StatisticDescriptor> f) {
return this->resource->getRawBits(f);
}
void ResourceInst::writeSample() {
bool wroteInstId = false;
bool checkForChange = true;
- StatisticDescriptor **stats = type->getStats();
+ auto &stats = type->getStats();
if (resource->isClosed()) {
return;
}
@@ -212,7 +213,7 @@ void ResourceInst::writeSample() {
checkForChange = false;
}
auto count = type->getNumOfDescriptors();
- for (int32_t i = 0; i < count; i++) {
+ for (decltype(count) i = 0; i < count; i++) {
int64_t value = getStatValue(stats[i]);
if (!checkForChange || value != archivedStatValues[i]) {
int64_t delta = value - archivedStatValues[i];
@@ -221,7 +222,7 @@ void ResourceInst::writeSample() {
wroteInstId = true;
writeResourceInst(dataOut, id);
}
- dataOut->writeByte(i);
+ dataOut->writeByte(static_cast<int8_t>(i));
writeStatValue(stats[i], delta);
}
}
@@ -230,9 +231,10 @@ void ResourceInst::writeSample() {
}
}
-void ResourceInst::writeStatValue(StatisticDescriptor *sd, int64_t v) {
- auto sdImpl = static_cast<StatisticDescriptorImpl *>(sd);
- if (sdImpl == nullptr) {
+void ResourceInst::writeStatValue(std::shared_ptr<StatisticDescriptor> sd,
+ int64_t v) {
+ auto sdImpl = std::static_pointer_cast<StatisticDescriptorImpl>(sd);
+ if (!sdImpl) {
throw NullPointerException("could not downcast to
StatisticDescriptorImpl");
}
FieldType typeCode = sdImpl->getTypeCode();
@@ -583,10 +585,10 @@ const ResourceType
*StatArchiveWriter::getResourceType(const Statistics *s) {
auto stats = rt->getStats();
auto descCnt = rt->getNumOfDescriptors();
this->dataBuffer->writeShort(static_cast<int16_t>(descCnt));
- for (int32_t i = 0; i < descCnt; i++) {
+ for (decltype(descCnt) i = 0; i < descCnt; i++) {
std::string statsName = stats[i]->getName();
this->dataBuffer->writeUTF(statsName);
- auto sdImpl = static_cast<StatisticDescriptorImpl *>(stats[i]);
+ auto sdImpl =
std::static_pointer_cast<StatisticDescriptorImpl>(stats[i]);
if (sdImpl == nullptr) {
throw NullPointerException(
"could not down cast to StatisticDescriptorImpl");
diff --git a/cppcache/src/statistics/StatArchiveWriter.hpp
b/cppcache/src/statistics/StatArchiveWriter.hpp
index 4f8c2a3..5a98c0c 100644
--- a/cppcache/src/statistics/StatArchiveWriter.hpp
+++ b/cppcache/src/statistics/StatArchiveWriter.hpp
@@ -23,6 +23,7 @@
#include <chrono>
#include <list>
#include <map>
+#include <vector>
#include <geode/Cache.hpp>
#include <geode/DataOutput.hpp>
@@ -148,13 +149,12 @@ class APACHE_GEODE_EXPORT ResourceType : private
NonCopyable,
public:
ResourceType(int32_t id, const StatisticsType *type);
int32_t getId() const;
- StatisticDescriptor **getStats() const;
- int32_t getNumOfDescriptors() const;
+ const std::vector<std::shared_ptr<StatisticDescriptor>> &getStats() const;
+ size_t getNumOfDescriptors() const;
private:
int32_t id;
- StatisticDescriptor **stats;
- int32_t numOfDescriptors;
+ const StatisticsType *type;
};
/* adongre
@@ -180,9 +180,9 @@ class APACHE_GEODE_EXPORT ResourceInst : private
NonCopyable,
int32_t getId();
Statistics *getResource();
const ResourceType *getType() const;
- int64_t getStatValue(StatisticDescriptor *f);
+ int64_t getStatValue(std::shared_ptr<StatisticDescriptor> f);
void writeSample();
- void writeStatValue(StatisticDescriptor *s, int64_t v);
+ void writeStatValue(std::shared_ptr<StatisticDescriptor> s, int64_t v);
void writeCompactValue(int64_t v);
void writeResourceInst(StatDataOutput *, int32_t);
@@ -223,7 +223,8 @@ class APACHE_GEODE_EXPORT StatArchiveWriter {
void resampleResources();
void writeResourceInst(StatDataOutput *, int32_t);
void writeTimeStamp(const steady_clock::time_point &timeStamp);
- void writeStatValue(StatisticDescriptor *f, int64_t v, DataOutput dataOut);
+ void writeStatValue(std::shared_ptr<StatisticDescriptor> f, int64_t v,
+ DataOutput dataOut);
const ResourceType *getResourceType(const Statistics *);
bool resourceInstMapHas(Statistics *sp);
diff --git a/cppcache/src/statistics/StatSamplerStats.cpp
b/cppcache/src/statistics/StatSamplerStats.cpp
index 5a86fb0..e3cd324 100644
--- a/cppcache/src/statistics/StatSamplerStats.cpp
+++ b/cppcache/src/statistics/StatSamplerStats.cpp
@@ -24,7 +24,7 @@ namespace geode {
namespace statistics {
StatSamplerStats::StatSamplerStats(StatisticsFactory* statFactory) {
- statDescriptorArr = new StatisticDescriptor*[2];
+ std::vector<std::shared_ptr<StatisticDescriptor>> statDescriptorArr(2);
statDescriptorArr[0] = statFactory->createIntCounter(
"sampleCount", "Total number of samples taken by this sampler.",
"samples", false);
@@ -35,7 +35,7 @@ StatSamplerStats::StatSamplerStats(StatisticsFactory*
statFactory) {
samplerType =
statFactory->createType("StatSampler", "Stats on the statistic sampler.",
- StatSamplerStats::statDescriptorArr, 2);
+ std::move(statDescriptorArr));
sampleCountId = samplerType->nameToId("sampleCount");
sampleTimeId = samplerType->nameToId("sampleTime");
this->samplerStats = statFactory->createStatistics(samplerType,
"statSampler",
@@ -64,9 +64,6 @@ void StatSamplerStats::close() {
StatSamplerStats::~StatSamplerStats() {
samplerType = nullptr;
- for (int32_t i = 0; i < 2; i++) {
- statDescriptorArr[i] = nullptr;
- }
samplerStats = nullptr;
}
diff --git a/cppcache/src/statistics/StatSamplerStats.hpp
b/cppcache/src/statistics/StatSamplerStats.hpp
index b942aa6..9a5cb8d 100644
--- a/cppcache/src/statistics/StatSamplerStats.hpp
+++ b/cppcache/src/statistics/StatSamplerStats.hpp
@@ -42,7 +42,6 @@ class APACHE_GEODE_EXPORT StatSamplerStats {
Statistics* samplerStats;
int32_t sampleCountId;
int32_t sampleTimeId;
- StatisticDescriptor** statDescriptorArr;
public:
explicit StatSamplerStats(StatisticsFactory* statFactory);
diff --git a/cppcache/src/statistics/StatisticDescriptorImpl.cpp
b/cppcache/src/statistics/StatisticDescriptorImpl.cpp
index 7da27a9..32cfb3a 100644
--- a/cppcache/src/statistics/StatisticDescriptorImpl.cpp
+++ b/cppcache/src/statistics/StatisticDescriptorImpl.cpp
@@ -57,83 +57,63 @@ StatisticDescriptorImpl::~StatisticDescriptorImpl() {}
/////////////////////// Create functions ///////////////////////////////////
-StatisticDescriptor* StatisticDescriptorImpl::createIntCounter(
+std::shared_ptr<StatisticDescriptor> StatisticDescriptorImpl::createCounter(
+ const std::string& statName, FieldType fieldType,
+ const std::string& description, const std::string& units,
+ bool statIsCounter, bool isLargerBetter) {
+ auto sdi = new StatisticDescriptorImpl(statName, fieldType, description,
+ units, statIsCounter, isLargerBetter);
+ return std::shared_ptr<StatisticDescriptorImpl>(sdi);
+}
+
+std::shared_ptr<StatisticDescriptor> StatisticDescriptorImpl::createIntCounter(
const std::string& statName, const std::string& description,
const std::string& units, bool isLargerBetter) {
FieldType fieldType = INT_TYPE;
- StatisticDescriptorImpl* sdi = new StatisticDescriptorImpl(
- statName, fieldType, description, units, true, isLargerBetter);
- if (sdi == nullptr) {
- throw OutOfMemoryException(
- "StatisticDescriptorImpl::createIntCounter: out of memory");
- }
- return sdi;
+ return createCounter(statName, fieldType, description, units, true,
+ isLargerBetter);
}
-StatisticDescriptor* StatisticDescriptorImpl::createLongCounter(
+std::shared_ptr<StatisticDescriptor>
StatisticDescriptorImpl::createLongCounter(
const std::string& name, const std::string& description,
const std::string& units, bool isLargerBetter) {
FieldType fieldType = LONG_TYPE;
- StatisticDescriptorImpl* sdi = new StatisticDescriptorImpl(
- name, fieldType, description, units, true, isLargerBetter);
- if (sdi == nullptr) {
- throw OutOfMemoryException(
- "StatisticDescriptorImpl::createLongCounter: out of memory");
- }
- return sdi;
+ return createCounter(name, fieldType, description, units, true,
+ isLargerBetter);
}
-StatisticDescriptor* StatisticDescriptorImpl::createDoubleCounter(
- const std::string& name, const std::string& description,
- const std::string& units, bool isLargerBetter) {
+std::shared_ptr<StatisticDescriptor>
+StatisticDescriptorImpl::createDoubleCounter(const std::string& name,
+ const std::string& description,
+ const std::string& units,
+ bool isLargerBetter) {
FieldType fieldType = DOUBLE_TYPE;
- StatisticDescriptorImpl* sdi = new StatisticDescriptorImpl(
- name, fieldType, description, units, true, isLargerBetter);
- if (sdi == nullptr) {
- throw OutOfMemoryException(
- "StatisticDescriptorImpl::createDoubleCounter: out of memory");
- }
- return sdi;
+ return createCounter(name, fieldType, description, units, true,
+ isLargerBetter);
}
-StatisticDescriptor* StatisticDescriptorImpl::createIntGauge(
+std::shared_ptr<StatisticDescriptor> StatisticDescriptorImpl::createIntGauge(
const std::string& name, const std::string& description,
const std::string& units, bool isLargerBetter) {
FieldType fieldType = INT_TYPE;
- StatisticDescriptorImpl* sdi = new StatisticDescriptorImpl(
- name, fieldType, description, units, false, isLargerBetter);
- if (sdi == nullptr) {
- throw OutOfMemoryException(
- "StatisticDescriptorImpl::createIntGauge: out of memory");
- }
- return sdi;
+ return createCounter(name, fieldType, description, units, false,
+ isLargerBetter);
}
-StatisticDescriptor* StatisticDescriptorImpl::createLongGauge(
+std::shared_ptr<StatisticDescriptor> StatisticDescriptorImpl::createLongGauge(
const std::string& name, const std::string& description,
const std::string& units, bool isLargerBetter) {
FieldType fieldType = LONG_TYPE;
- StatisticDescriptorImpl* sdi = new StatisticDescriptorImpl(
- name, fieldType, description, units, false, isLargerBetter);
-
- if (sdi == nullptr) {
- throw OutOfMemoryException(
- "StatisticDescriptorImpl::createLongGauge: out of memory");
- }
- return sdi;
+ return createCounter(name, fieldType, description, units, false,
+ isLargerBetter);
}
-StatisticDescriptor* StatisticDescriptorImpl::createDoubleGauge(
+std::shared_ptr<StatisticDescriptor>
StatisticDescriptorImpl::createDoubleGauge(
const std::string& name, const std::string& description,
const std::string& units, bool isLargerBetter) {
FieldType fieldType = DOUBLE_TYPE;
- StatisticDescriptorImpl* sdi = new StatisticDescriptorImpl(
- name, fieldType, description, units, false, isLargerBetter);
- if (sdi == nullptr) {
- throw OutOfMemoryException(
- "StatisticDescriptorImpl::createDoubleGauge: out of memory");
- }
- return sdi;
+ return createCounter(name, fieldType, description, units, false,
+ isLargerBetter);
}
/////////////////////// StatisticDescriptor(Base class)
diff --git a/cppcache/src/statistics/StatisticDescriptorImpl.hpp
b/cppcache/src/statistics/StatisticDescriptorImpl.hpp
index 8f49ec2..3fe72b6 100644
--- a/cppcache/src/statistics/StatisticDescriptorImpl.hpp
+++ b/cppcache/src/statistics/StatisticDescriptorImpl.hpp
@@ -101,6 +101,11 @@ class StatisticDescriptorImpl : public StatisticDescriptor
{
const std::string& statUnit, bool statIsCounter,
bool statIsLargerBetter);
+ static std::shared_ptr<StatisticDescriptor> createCounter(
+ const std::string& statName, FieldType fieldType,
+ const std::string& description, const std::string& units,
+ bool statIsCounter, bool isLargerBetter);
+
public:
/** GfFieldType defined in geode.h.
* It describes the date type of an individual descriptor.
@@ -139,27 +144,25 @@ class StatisticDescriptorImpl : public
StatisticDescriptor {
* whose value behaves like a counter
* @throws OutOfMemoryException
*/
- static StatisticDescriptor* createIntCounter(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool isLargerBetter);
+ static std::shared_ptr<StatisticDescriptor> createIntCounter(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool isLargerBetter);
/**
* Creates a descriptor of Long type
* whose value behaves like a counter
* @throws OutOfMemoryException
*/
- static StatisticDescriptor* createLongCounter(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool isLargerBetter);
+ static std::shared_ptr<StatisticDescriptor> createLongCounter(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool isLargerBetter);
/**
* Creates a descriptor of Double type
* whose value behaves like a counter
* @throws OutOfMemoryException
*/
- static StatisticDescriptor* createDoubleCounter(
+ static std::shared_ptr<StatisticDescriptor> createDoubleCounter(
const std::string& name, const std::string& description,
const std::string& units, bool isLargerBetter);
@@ -168,30 +171,27 @@ class StatisticDescriptorImpl : public
StatisticDescriptor {
* whose value behaves like a gauge
* @throws OutOfMemoryException
*/
- static StatisticDescriptor* createIntGauge(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool isLargerBetter);
+ static std::shared_ptr<StatisticDescriptor> createIntGauge(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool isLargerBetter);
/**
* Creates a descriptor of Long type
* whose value behaves like a gauge
* @throws OutOfMemoryException
*/
- static StatisticDescriptor* createLongGauge(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool isLargerBetter);
+ static std::shared_ptr<StatisticDescriptor> createLongGauge(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool isLargerBetter);
/**
* Creates a descriptor of Double type
* whose value behaves like a gauge
* @throws OutOfMemoryException
*/
- static StatisticDescriptor* createDoubleGauge(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool isLargerBetter);
+ static std::shared_ptr<StatisticDescriptor> createDoubleGauge(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool isLargerBetter);
///////////////// StatisticDescriptor(Base class) Methods
///////////////////////
diff --git a/cppcache/src/statistics/Statistics.cpp
b/cppcache/src/statistics/Statistics.cpp
index bfc5dbf..c52aa00 100644
--- a/cppcache/src/statistics/Statistics.cpp
+++ b/cppcache/src/statistics/Statistics.cpp
@@ -27,7 +27,8 @@ void Statistics::close() {}
int32_t Statistics::nameToId(const std::string&) const { return 0; }
-StatisticDescriptor* Statistics::nameToDescriptor(const std::string&) const {
+std::shared_ptr<StatisticDescriptor> Statistics::nameToDescriptor(
+ const std::string&) const {
return nullptr;
}
@@ -54,17 +55,18 @@ void Statistics::setInt(int32_t, int32_t) {}
void Statistics::setInt(const std::string&, int32_t) {}
-void Statistics::setInt(const StatisticDescriptor*, int32_t) {}
+void Statistics::setInt(const std::shared_ptr<StatisticDescriptor>, int32_t) {}
void Statistics::setLong(int32_t, int64_t) {}
-void Statistics::setLong(const StatisticDescriptor*, int64_t) {}
+void Statistics::setLong(const std::shared_ptr<StatisticDescriptor>, int64_t)
{}
void Statistics::setLong(const std::string&, int64_t) {}
void Statistics::setDouble(int32_t, double) {}
-void Statistics::setDouble(const StatisticDescriptor*, double) {}
+void Statistics::setDouble(const std::shared_ptr<StatisticDescriptor>, double)
{
+}
void setDouble(const std::string&, double) {}
@@ -72,19 +74,25 @@ void setDouble(const std::string&, double) {}
int32_t Statistics::getInt(int32_t) const { return 0; }
-int32_t Statistics::getInt(const StatisticDescriptor*) const { return 0; }
+int32_t Statistics::getInt(const std::shared_ptr<StatisticDescriptor>) const {
+ return 0;
+}
int32_t Statistics::getInt(const std::string&) const { return 0; }
int64_t Statistics::getLong(int32_t) const { return 0; }
-int64_t Statistics::getLong(const StatisticDescriptor*) const { return 0; }
+int64_t Statistics::getLong(const std::shared_ptr<StatisticDescriptor>) const {
+ return 0;
+}
int64_t Statistics::getLong(const std::string&) const { return 0; }
double Statistics::getDouble(int32_t) const { return 0; }
-double Statistics::getDouble(const StatisticDescriptor*) const { return 0; }
+double Statistics::getDouble(const std::shared_ptr<StatisticDescriptor>) const
{
+ return 0;
+}
double Statistics::getDouble(const std::string&) const { return 0; }
@@ -104,19 +112,28 @@ double Statistics::getDouble(const std::string&) const {
return 0; }
*/
int32_t Statistics::incInt(int32_t, int32_t) { return 0; }
-int32_t Statistics::incInt(const StatisticDescriptor*, int32_t) { return 0; }
+int32_t Statistics::incInt(const std::shared_ptr<StatisticDescriptor>,
+ int32_t) {
+ return 0;
+}
int32_t Statistics::incInt(const std::string&, int32_t) { return 0; }
int64_t Statistics::incLong(int32_t, int64_t) { return 0; }
-int64_t Statistics::incLong(const StatisticDescriptor*, int64_t) { return 0; }
+int64_t Statistics::incLong(const std::shared_ptr<StatisticDescriptor>,
+ int64_t) {
+ return 0;
+}
int64_t Statistics::incLong(const std::string&, int64_t) { return 0; }
double Statistics::incDouble(int32_t, double) { return 0; }
-double Statistics::incDouble(const StatisticDescriptor*, double) { return 0; }
+double Statistics::incDouble(const std::shared_ptr<StatisticDescriptor>,
+ double) {
+ return 0;
+}
double Statistics::incDouble(const std::string&, double) { return 0; }
diff --git a/cppcache/src/statistics/Statistics.hpp
b/cppcache/src/statistics/Statistics.hpp
index 58ae626..4ea90ef 100644
--- a/cppcache/src/statistics/Statistics.hpp
+++ b/cppcache/src/statistics/Statistics.hpp
@@ -76,7 +76,7 @@ class APACHE_GEODE_EXPORT Statistics {
*
* @see StatisticsType#nameToId
*/
- virtual StatisticDescriptor* nameToDescriptor(
+ virtual std::shared_ptr<StatisticDescriptor> nameToDescriptor(
const std::string& name) const = 0;
/**
@@ -162,7 +162,8 @@ class APACHE_GEODE_EXPORT Statistics {
* if the described statistic is not of
* type <code>int</code>.
*/
- virtual void setInt(const StatisticDescriptor* descriptor, int32_t value) =
0;
+ virtual void setInt(const std::shared_ptr<StatisticDescriptor> descriptor,
+ int32_t value) = 0;
/**
* Sets the value of a statistic with the given <code>id</code>
@@ -188,7 +189,7 @@ class APACHE_GEODE_EXPORT Statistics {
* if the described statistic is not of
* type <code>long</code>.
*/
- virtual void setLong(const StatisticDescriptor* descriptor,
+ virtual void setLong(const std::shared_ptr<StatisticDescriptor> descriptor,
int64_t value) = 0;
/**
@@ -227,7 +228,7 @@ class APACHE_GEODE_EXPORT Statistics {
* if the described statistic is not of
* type <code>double</code>.
*/
- virtual void setDouble(const StatisticDescriptor* descriptor,
+ virtual void setDouble(const std::shared_ptr<StatisticDescriptor> descriptor,
double value) = 0;
/**
@@ -266,7 +267,8 @@ class APACHE_GEODE_EXPORT Statistics {
* if the described statistic is not of
* type <code>int</code>.
*/
- virtual int32_t getInt(const StatisticDescriptor* descriptor) const = 0;
+ virtual int32_t getInt(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const = 0;
/**
* Returns the value of the statistic of type <code>int</code> at
@@ -302,7 +304,8 @@ class APACHE_GEODE_EXPORT Statistics {
* if the described statistic is not of
* type <code>long</code>.
*/
- virtual int64_t getLong(const StatisticDescriptor* descriptor) const = 0;
+ virtual int64_t getLong(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const = 0;
/**
* Returns the value of the statistic of type <code>long</code> at
@@ -338,7 +341,8 @@ class APACHE_GEODE_EXPORT Statistics {
* if the described statistic is not of
* type <code>double</code>.
*/
- virtual double getDouble(const StatisticDescriptor* descriptor) const = 0;
+ virtual double getDouble(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const = 0;
/**
* Returns the value of the statistic of type <code>double</code> at
@@ -361,7 +365,8 @@ class APACHE_GEODE_EXPORT Statistics {
* @throws IllegalArgumentException
* If the described statistic does not exist
*/
- virtual int64_t getRawBits(const StatisticDescriptor* descriptor) const = 0;
+ virtual int64_t getRawBits(
+ const std::shared_ptr<StatisticDescriptor> descriptor) const = 0;
//////////////////////// inc() Methods ////////////////////////
@@ -394,7 +399,7 @@ class APACHE_GEODE_EXPORT Statistics {
* if the described statistic is not of
* type <code>int</code>.
*/
- virtual int32_t incInt(const StatisticDescriptor* descriptor,
+ virtual int32_t incInt(const std::shared_ptr<StatisticDescriptor> descriptor,
int32_t delta) = 0;
/**
@@ -441,7 +446,7 @@ class APACHE_GEODE_EXPORT Statistics {
* if the described statistic is not of
* type <code>long</code>.
*/
- virtual int64_t incLong(const StatisticDescriptor* descriptor,
+ virtual int64_t incLong(const std::shared_ptr<StatisticDescriptor>
descriptor,
int64_t delta) = 0;
/**
* Increments the value of the statistic of type <code>long</code> with
@@ -489,8 +494,8 @@ class APACHE_GEODE_EXPORT Statistics {
* if the described statistic is not of
* type <code>double</code>.
*/
- virtual double incDouble(const StatisticDescriptor* descriptor,
- double delta) = 0;
+ virtual double incDouble(
+ const std::shared_ptr<StatisticDescriptor> descriptor, double delta) = 0;
/**
* Increments the value of the statistic of type <code>double</code> with
* the given name by a given amount.
diff --git a/cppcache/src/statistics/StatisticsFactory.hpp
b/cppcache/src/statistics/StatisticsFactory.hpp
index 30b88b8..0cd4549 100644
--- a/cppcache/src/statistics/StatisticsFactory.hpp
+++ b/cppcache/src/statistics/StatisticsFactory.hpp
@@ -20,6 +20,8 @@
#ifndef GEODE_STATISTICS_STATISTICSFACTORY_H_
#define GEODE_STATISTICS_STATISTICSFACTORY_H_
+#include <vector>
+
#include <geode/ExceptionTypes.hpp>
#include <geode/internal/geode_globals.hpp>
@@ -67,10 +69,9 @@ class APACHE_GEODE_EXPORT StatisticsFactory {
* <code>units</code>,and with larger values indicating better performance.
*/
- virtual StatisticDescriptor* createIntCounter(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool largerBetter = true) = 0;
+ virtual std::shared_ptr<StatisticDescriptor> createIntCounter(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter = true) = 0;
/**
* Creates and returns a double counter {@link StatisticDescriptor}
@@ -78,10 +79,9 @@ class APACHE_GEODE_EXPORT StatisticsFactory {
*<code>units</code>, and with larger values indicating better performance.
*/
- virtual StatisticDescriptor* createLongCounter(const std::string& name,
- const std::string&
description,
- const std::string& units,
- bool largerBetter = true) = 0;
+ virtual std::shared_ptr<StatisticDescriptor> createLongCounter(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter = true) = 0;
/**
* Creates and returns an int gauge {@link StatisticDescriptor}
@@ -90,7 +90,7 @@ class APACHE_GEODE_EXPORT StatisticsFactory {
* performance.
*/
- virtual StatisticDescriptor* createDoubleCounter(
+ virtual std::shared_ptr<StatisticDescriptor> createDoubleCounter(
const std::string& name, const std::string& description,
const std::string& units, bool largerBetter = true) = 0;
@@ -99,30 +99,27 @@ class APACHE_GEODE_EXPORT StatisticsFactory {
* with the given <code>name</code>, <code>description</code>,
* <code>units</code>, and with smaller values indicating better
performance.
*/
- virtual StatisticDescriptor* createIntGauge(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool largerBetter = false) = 0;
+ virtual std::shared_ptr<StatisticDescriptor> createIntGauge(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter = false) = 0;
/**
* Creates and returns an long gauge {@link StatisticDescriptor}
* with the given <code>name</code>, <code>description</code>,
* <code>units</code>, and with smaller values indicating better
performance.
*/
- virtual StatisticDescriptor* createLongGauge(const std::string& name,
- const std::string& description,
- const std::string& units,
- bool largerBetter = false) = 0;
+ virtual std::shared_ptr<StatisticDescriptor> createLongGauge(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter = false) = 0;
/**
* Creates and returns an double gauge {@link StatisticDescriptor}
* with the given <code>name</code>, <code>description</code>,
* <code>units</code>, and with smaller values indicating better
performance.
*/
- virtual StatisticDescriptor* createDoubleGauge(const std::string& name,
- const std::string&
description,
- const std::string& units,
- bool largerBetter = false) =
0;
+ virtual std::shared_ptr<StatisticDescriptor> createDoubleGauge(
+ const std::string& name, const std::string& description,
+ const std::string& units, bool largerBetter = false) = 0;
/**
* Creates and returns a {@link StatisticsType}
@@ -131,10 +128,9 @@ class APACHE_GEODE_EXPORT StatisticsFactory {
* @throws IllegalArgumentException
* if a type with the given <code>name</code> already exists.
*/
- virtual StatisticsType* createType(const std::string& name,
- const std::string& description,
- StatisticDescriptor** stats,
- int32_t statsLength) = 0;
+ virtual StatisticsType* createType(
+ const std::string& name, const std::string& description,
+ std::vector<std::shared_ptr<StatisticDescriptor>> stats) = 0;
/**
* Finds and returns an already created {@link StatisticsType}
diff --git a/cppcache/src/statistics/StatisticsType.hpp
b/cppcache/src/statistics/StatisticsType.hpp
index e002cf1..4a46475 100644
--- a/cppcache/src/statistics/StatisticsType.hpp
+++ b/cppcache/src/statistics/StatisticsType.hpp
@@ -20,6 +20,9 @@
#ifndef GEODE_STATISTICS_STATISTICSTYPE_H_
#define GEODE_STATISTICS_STATISTICSTYPE_H_
+#include <memory>
+#include <vector>
+
#include <geode/internal/geode_globals.hpp>
#include "StatisticDescriptor.hpp"
@@ -57,7 +60,8 @@ class APACHE_GEODE_EXPORT StatisticsType {
* Returns descriptions of the statistics that this statistics type
* gathers together.
*/
- virtual StatisticDescriptor** getStatistics() const = 0;
+ virtual const std::vector<std::shared_ptr<StatisticDescriptor>>&
+ getStatistics() const = 0;
/**
* Returns the id of the statistic with the given name in this
@@ -76,13 +80,13 @@ class APACHE_GEODE_EXPORT StatisticsType {
* No statistic named <code>name</code> exists in this
* statistics instance.
*/
- virtual StatisticDescriptor* nameToDescriptor(
+ virtual std::shared_ptr<StatisticDescriptor> nameToDescriptor(
const std::string& name) const = 0;
/**
* Returns the total number of statistics descriptors in the type.
*/
- virtual int32_t getDescriptorsCount() const = 0;
+ virtual size_t getDescriptorsCount() const = 0;
// protected:
/**
diff --git a/cppcache/src/statistics/StatisticsTypeImpl.cpp
b/cppcache/src/statistics/StatisticsTypeImpl.cpp
index 200cdde..e64546e 100644
--- a/cppcache/src/statistics/StatisticsTypeImpl.cpp
+++ b/cppcache/src/statistics/StatisticsTypeImpl.cpp
@@ -29,36 +29,28 @@ namespace statistics {
using client::IllegalArgumentException;
using client::NullPointerException;
-StatisticsTypeImpl::StatisticsTypeImpl(std::string nameArg,
- std::string descriptionArg,
- StatisticDescriptor** statsArg,
- int32_t statsLengthArg) {
+StatisticsTypeImpl::StatisticsTypeImpl(
+ std::string nameArg, std::string descriptionArg,
+ std::vector<std::shared_ptr<StatisticDescriptor>> statsArg) {
if (nameArg.empty()) {
const char* s = "Cannot have an empty statistics type name";
throw NullPointerException(s);
}
- if (statsArg == nullptr) {
- const char* s = "Cannot have a null statistic descriptors";
- throw NullPointerException(s);
- }
- if (statsLengthArg > MAX_DESCRIPTORS_PER_TYPE) {
+ if (stats.size() > MAX_DESCRIPTORS_PER_TYPE) {
throw IllegalArgumentException(
- "The requested descriptor count " + std::to_string(statsLengthArg) +
+ "The requested descriptor count " + std::to_string(stats.size()) +
" exceeds the maximum which is " +
std::to_string(MAX_DESCRIPTORS_PER_TYPE) + ".");
}
this->name = nameArg;
this->description = descriptionArg;
- this->stats = statsArg;
- this->statsLength = statsLengthArg;
+ this->stats = std::move(statsArg);
int32_t intCount = 0;
int32_t longCount = 0;
int32_t doubleCount = 0;
- for (int32_t i = 0; i < this->statsLength; i++) {
+ for (auto stat : stats) {
// Concrete class required to set the ids only.
- StatisticDescriptorImpl* sd =
- dynamic_cast<StatisticDescriptorImpl*>(stats[i]);
- if (sd != nullptr) {
+ if (auto sd = std::dynamic_pointer_cast<StatisticDescriptorImpl>(stat)) {
if (sd->getTypeCode() == INT_TYPE) {
sd->setId(intCount);
intCount++;
@@ -69,7 +61,7 @@ StatisticsTypeImpl::StatisticsTypeImpl(std::string nameArg,
sd->setId(doubleCount);
doubleCount++;
}
- std::string str = stats[i]->getName();
+ std::string str = stat->getName();
StatisticsDescMap::iterator iterFind = statsDescMap.find(str);
if (iterFind != statsDescMap.end()) {
throw IllegalArgumentException("Duplicate StatisticDescriptor named " +
@@ -77,7 +69,7 @@ StatisticsTypeImpl::StatisticsTypeImpl(std::string nameArg,
} else {
// statsDescMap.insert(make_pair(stats[i]->getName(), stats[i]));
statsDescMap.insert(
- StatisticsDescMap::value_type(stats[i]->getName(), stats[i]));
+ StatisticsDescMap::value_type(stat->getName(), stat));
}
}
} // for
@@ -86,21 +78,7 @@ StatisticsTypeImpl::StatisticsTypeImpl(std::string nameArg,
this->doubleStatCount = doubleCount;
}
-StatisticsTypeImpl::~StatisticsTypeImpl() {
- try {
- // Delete the descriptor pointers from the array
- for (int32_t i = 0; i < statsLength; i++) {
- delete stats[i];
- stats[i] = nullptr;
- }
- // same pointers are also stored in this map.
- // So, Set the pointers to null.
- for (auto& it : statsDescMap) {
- it.second = nullptr;
- }
- } catch (...) {
- }
-}
+StatisticsTypeImpl::~StatisticsTypeImpl() {}
const std::string& StatisticsTypeImpl::getName() const { return name; }
@@ -108,7 +86,8 @@ const std::string& StatisticsTypeImpl::getDescription()
const {
return description;
}
-StatisticDescriptor** StatisticsTypeImpl::getStatistics() const {
+const std::vector<std::shared_ptr<StatisticDescriptor>>&
+StatisticsTypeImpl::getStatistics() const {
return stats;
}
@@ -116,7 +95,7 @@ int32_t StatisticsTypeImpl::nameToId(const std::string&
nameArg) const {
return nameToDescriptor(nameArg)->getId();
}
-StatisticDescriptor* StatisticsTypeImpl::nameToDescriptor(
+std::shared_ptr<StatisticDescriptor> StatisticsTypeImpl::nameToDescriptor(
const std::string& nameArg) const {
const auto iterFind = statsDescMap.find(nameArg);
if (iterFind == statsDescMap.end()) {
@@ -137,7 +116,7 @@ int32_t StatisticsTypeImpl::getDoubleStatCount() const {
return doubleStatCount;
}
-int32_t StatisticsTypeImpl::getDescriptorsCount() const { return statsLength; }
+size_t StatisticsTypeImpl::getDescriptorsCount() const { return stats.size(); }
} // namespace statistics
} // namespace geode
diff --git a/cppcache/src/statistics/StatisticsTypeImpl.hpp
b/cppcache/src/statistics/StatisticsTypeImpl.hpp
index 2c25981..19a8d73 100644
--- a/cppcache/src/statistics/StatisticsTypeImpl.hpp
+++ b/cppcache/src/statistics/StatisticsTypeImpl.hpp
@@ -22,6 +22,7 @@
#include <map>
#include <string>
+#include <vector>
#include <geode/ExceptionTypes.hpp>
@@ -42,14 +43,14 @@ namespace statistics {
*
*/
-typedef std::map<std::string, StatisticDescriptor*> StatisticsDescMap;
+typedef std::map<std::string, std::shared_ptr<StatisticDescriptor>>
+ StatisticsDescMap;
class StatisticsTypeImpl : public StatisticsType {
private:
- int32_t statsLength;
std::string name;
std::string description;
- StatisticDescriptor** stats;
+ std::vector<std::shared_ptr<StatisticDescriptor>> stats;
StatisticsDescMap statsDescMap;
int32_t intStatCount;
int32_t longStatCount;
@@ -57,7 +58,7 @@ class StatisticsTypeImpl : public StatisticsType {
public:
StatisticsTypeImpl(std::string name, std::string description,
- StatisticDescriptor** stats, int32_t statsLength);
+ std::vector<std::shared_ptr<StatisticDescriptor>> stats);
~StatisticsTypeImpl() override;
@@ -67,11 +68,13 @@ class StatisticsTypeImpl : public StatisticsType {
const std::string& getDescription() const override;
- StatisticDescriptor** getStatistics() const override;
+ const std::vector<std::shared_ptr<StatisticDescriptor>>& getStatistics()
+ const override;
int32_t nameToId(const std::string& name) const override;
- StatisticDescriptor* nameToDescriptor(const std::string& name) const
override;
+ std::shared_ptr<StatisticDescriptor> nameToDescriptor(
+ const std::string& name) const override;
////////////////////// Instance Methods //////////////////////
@@ -93,7 +96,7 @@ class StatisticsTypeImpl : public StatisticsType {
/*
* Gets the total number of statistic descriptors in the Type
*/
- int32_t getDescriptorsCount() const override;
+ size_t getDescriptorsCount() const override;
// static StatisticsType[] fromXml(Reader reader,
// StatisticsTypeFactory factory);
diff --git a/tests/cpp/testobject/PdxType.cpp b/tests/cpp/testobject/PdxType.cpp
index 753eae4..496a948 100644
--- a/tests/cpp/testobject/PdxType.cpp
+++ b/tests/cpp/testobject/PdxType.cpp
@@ -173,13 +173,12 @@ void PdxTests::PdxType::toData(PdxWriter& pw) const {
}
void PdxTests::PdxType::fromData(PdxReader& pr) {
- // TODO:temp added, delete later
-
int32_t* Lengtharr;
- _GEODE_NEW(Lengtharr, int32_t[2]);
int32_t arrLen = 0;
+ deleteByteByteArray();
m_byteByteArray =
pr.readArrayOfByteArrays("m_byteByteArray", arrLen, &Lengtharr);
+ _GEODE_SAFE_DELETE_ARRAY(Lengtharr);
// TODO::need to write compareByteByteArray() and check for m_byteByteArray
// elements
diff --git a/tests/cpp/testobject/PdxType.hpp b/tests/cpp/testobject/PdxType.hpp
index 7efbe31..8b7d5b9 100644
--- a/tests/cpp/testobject/PdxType.hpp
+++ b/tests/cpp/testobject/PdxType.hpp
@@ -391,7 +391,7 @@ class TESTOBJECT_EXPORT PdxType : public PdxSerializable {
int32_t strLenArray;
int32_t byteByteArrayLen;
- int* lengthArr;
+ int lengthArr[2];
public:
inline void init() {
@@ -470,9 +470,6 @@ class TESTOBJECT_EXPORT PdxType : public PdxSerializable {
m_doubleArray[1] = 4324235435.00;
m_byteByteArray = new int8_t*[2];
- // for(int i=0; i<2; i++){
- // m_byteByteArray[i] = new int8_t[1];
- //}
m_byteByteArray[0] = new int8_t[1];
m_byteByteArray[1] = new int8_t[2];
m_byteByteArray[0][0] = 0x23;
@@ -606,8 +603,6 @@ class TESTOBJECT_EXPORT PdxType : public PdxSerializable {
charArrayLen = 2;
byteByteArrayLen = 2;
- lengthArr = new int[2];
-
lengthArr[0] = 1;
lengthArr[1] = 2;
}
@@ -619,7 +614,21 @@ class TESTOBJECT_EXPORT PdxType : public PdxSerializable {
throw IllegalStateException("Not got expected value for bool type: ");
}
- ~PdxType() override = default;
+ void deleteByteByteArray() {
+ if (m_byteByteArray == nullptr) {
+ return;
+ }
+ _GEODE_SAFE_DELETE_ARRAY(m_byteByteArray[0]);
+ _GEODE_SAFE_DELETE_ARRAY(m_byteByteArray[1]);
+ _GEODE_SAFE_DELETE_ARRAY(m_byteByteArray);
+ }
+
+ ~PdxType() override {
+ deleteByteByteArray();
+ for (auto i = 0; i <= 9; i++) {
+ _GEODE_SAFE_DELETE(m_add[i]);
+ }
+ };
virtual size_t objectSize() const override {
auto objectSize = sizeof(PdxType);