Skip to content

Commit

Permalink
Technically - These are not leaks as the Classes are static and inten…
Browse files Browse the repository at this point in the history
…ded to live for the lifetime of the application. But Lets cleanup so leak report is clean
  • Loading branch information
Fishwaldo committed Jun 19, 2019
1 parent 5fdefd8 commit eab8d30
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 61 deletions.
3 changes: 3 additions & 0 deletions cpp/build/support.mk
Expand Up @@ -81,6 +81,9 @@ endif
ifeq ($(UNAME),Darwin)
AR := libtool -static -o
RANLIB := ranlib
CC := clang
CXX := clang++
LD := clang++
else
AR := $(CROSS_COMPILE)ar rc
RANLIB := $(CROSS_COMPILE)ranlib
Expand Down
25 changes: 13 additions & 12 deletions cpp/src/Localization.cpp
Expand Up @@ -43,9 +43,9 @@ namespace OpenZWave
{

Localization *Localization::m_instance = NULL;
std::map<uint64, ValueLocalizationEntry*> Localization::m_valueLocalizationMap;
std::map<uint8, LabelLocalizationEntry*> Localization::m_commandClassLocalizationMap;
std::map<std::string, LabelLocalizationEntry*> Localization::m_globalLabelLocalizationMap;
std::map<uint64, std::shared_ptr<ValueLocalizationEntry> > Localization::m_valueLocalizationMap;
std::map<uint8, std::shared_ptr<LabelLocalizationEntry> > Localization::m_commandClassLocalizationMap;
std::map<std::string, std::shared_ptr<LabelLocalizationEntry> > Localization::m_globalLabelLocalizationMap;
std::string Localization::m_selectedLang = "";
uint32 Localization::m_revision = 0;

Expand Down Expand Up @@ -318,6 +318,7 @@ namespace OpenZWave
CCElement = CCElement->NextSiblingElement();
}
Log::Write(LogLevel_Info, "Loaded %s With Revision %d", pDoc->GetUserData(), m_revision);
delete pDoc;
}

void Localization::ReadGlobalXMLLabel(const TiXmlElement *labelElement)
Expand All @@ -334,7 +335,7 @@ namespace OpenZWave
Language = labelElement->Attribute("lang");
if (m_globalLabelLocalizationMap.find(str) == m_globalLabelLocalizationMap.end())
{
m_globalLabelLocalizationMap[str] = new LabelLocalizationEntry(0);
m_globalLabelLocalizationMap[str] = std::shared_ptr<LabelLocalizationEntry>(new LabelLocalizationEntry(0));
}
else if (m_globalLabelLocalizationMap[str]->HasLabel(Language))
{
Expand Down Expand Up @@ -362,7 +363,7 @@ namespace OpenZWave

if (m_commandClassLocalizationMap.find(ccID) == m_commandClassLocalizationMap.end())
{
m_commandClassLocalizationMap[ccID] = new LabelLocalizationEntry(0);
m_commandClassLocalizationMap[ccID] = std::shared_ptr<LabelLocalizationEntry>(new LabelLocalizationEntry(0));
}
else if (m_commandClassLocalizationMap[ccID]->HasLabel(Language))
{
Expand Down Expand Up @@ -434,7 +435,7 @@ namespace OpenZWave

if (m_valueLocalizationMap.find(key) == m_valueLocalizationMap.end())
{
m_valueLocalizationMap[key] = new ValueLocalizationEntry(ccID, indexId, pos);
m_valueLocalizationMap[key] = std::shared_ptr<ValueLocalizationEntry> (new ValueLocalizationEntry(ccID, indexId, pos));
}
else if (m_valueLocalizationMap[key]->HasLabel(Language))
{
Expand Down Expand Up @@ -472,7 +473,7 @@ namespace OpenZWave
uint64 key = GetValueKey(node, ccID, indexId, pos);
if (m_valueLocalizationMap.find(key) == m_valueLocalizationMap.end())
{
m_valueLocalizationMap[key] = new ValueLocalizationEntry(ccID, indexId, pos);
m_valueLocalizationMap[key] = std::shared_ptr<ValueLocalizationEntry> (new ValueLocalizationEntry(ccID, indexId, pos));
}
else if (m_valueLocalizationMap[key]->HasLabel(Language))
{
Expand Down Expand Up @@ -572,7 +573,7 @@ namespace OpenZWave
uint64 key = GetValueKey(_node, ccID, indexId, pos);
if (m_valueLocalizationMap.find(key) == m_valueLocalizationMap.end())
{
m_valueLocalizationMap[key] = new ValueLocalizationEntry(ccID, indexId, pos);
m_valueLocalizationMap[key] = std::shared_ptr<ValueLocalizationEntry> (new ValueLocalizationEntry(ccID, indexId, pos));
}
else if (m_valueLocalizationMap[key]->HasHelp(lang))
{
Expand All @@ -594,7 +595,7 @@ namespace OpenZWave
uint64 key = GetValueKey(node, ccID, indexId, pos);
if (m_valueLocalizationMap.find(key) == m_valueLocalizationMap.end())
{
m_valueLocalizationMap[key] = new ValueLocalizationEntry(ccID, indexId, pos);
m_valueLocalizationMap[key] = std::shared_ptr<ValueLocalizationEntry> (new ValueLocalizationEntry(ccID, indexId, pos));
}
else if (m_valueLocalizationMap[key]->HasLabel(lang))
{
Expand Down Expand Up @@ -661,7 +662,7 @@ namespace OpenZWave
uint64 key = GetValueKey(node, ccID, indexId, pos, unique);
if (m_valueLocalizationMap.find(key) == m_valueLocalizationMap.end())
{
m_valueLocalizationMap[key] = new ValueLocalizationEntry(ccID, indexId, pos);
m_valueLocalizationMap[key] = std::shared_ptr<ValueLocalizationEntry> (new ValueLocalizationEntry(ccID, indexId, pos));
}
else if (m_valueLocalizationMap[key]->HasItemLabel(itemIndex, lang))
{
Expand Down Expand Up @@ -699,7 +700,7 @@ namespace OpenZWave
uint64 key = GetValueKey(node, ccID, indexId, pos, unique);
if (m_valueLocalizationMap.find(key) == m_valueLocalizationMap.end())
{
m_valueLocalizationMap[key] = new ValueLocalizationEntry(ccID, indexId, pos);
m_valueLocalizationMap[key] = std::shared_ptr<ValueLocalizationEntry> (new ValueLocalizationEntry(ccID, indexId, pos));
}
else if (m_valueLocalizationMap[key]->HasItemHelp(itemIndex, lang))
{
Expand All @@ -723,7 +724,7 @@ namespace OpenZWave
{
if (m_globalLabelLocalizationMap.find(index) == m_globalLabelLocalizationMap.end())
{
m_globalLabelLocalizationMap[index] = new LabelLocalizationEntry(0);
m_globalLabelLocalizationMap[index] = std::shared_ptr<LabelLocalizationEntry>(new LabelLocalizationEntry(0));
}
else if (m_globalLabelLocalizationMap[index]->HasLabel(lang))
{
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/Localization.h
Expand Up @@ -136,9 +136,9 @@ namespace OpenZWave
//-----------------------------------------------------------------------------
private:
static Localization* m_instance;
static map<uint64, ValueLocalizationEntry*> m_valueLocalizationMap;
static map<uint8, LabelLocalizationEntry*> m_commandClassLocalizationMap;
static map<string, LabelLocalizationEntry*> m_globalLabelLocalizationMap;
static map<uint64, std::shared_ptr<ValueLocalizationEntry> > m_valueLocalizationMap;
static map<uint8, std::shared_ptr<LabelLocalizationEntry> > m_commandClassLocalizationMap;
static map<string, std::shared_ptr<LabelLocalizationEntry> > m_globalLabelLocalizationMap;
static string m_selectedLang;
static uint32 m_revision;

Expand Down
16 changes: 8 additions & 8 deletions cpp/src/ManufacturerSpecificDB.cpp
Expand Up @@ -43,7 +43,7 @@ namespace OpenZWave

ManufacturerSpecificDB *ManufacturerSpecificDB::s_instance = NULL;
std::map<uint16, std::string> ManufacturerSpecificDB::s_manufacturerMap;
std::map<int64, ProductDescriptor*> ManufacturerSpecificDB::s_productMap;
std::map<int64, std::shared_ptr<ProductDescriptor> > ManufacturerSpecificDB::s_productMap;
bool ManufacturerSpecificDB::s_bXmlLoaded = false;

ManufacturerSpecificDB *ManufacturerSpecificDB::Create()
Expand Down Expand Up @@ -235,14 +235,14 @@ namespace OpenZWave
ProductDescriptor* product = new ProductDescriptor(manufacturerId, productType, productId, productName, s_manufacturerMap[manufacturerId], dconfigPath);
if (s_productMap[product->GetKey()] != NULL)
{
ProductDescriptor *c = s_productMap[product->GetKey()];
std::shared_ptr<ProductDescriptor> c = s_productMap[product->GetKey()];
Log::Write(LogLevel_Info, "Product name collision: %s type %x id %x manufacturerid %x, collides with %s, type %x id %x manufacturerid %x", productName.c_str(), productType, productId, manufacturerId, c->GetProductName().c_str(), c->GetProductType(), c->GetProductId(), c->GetManufacturerId());
delete product;
}
else
{
LoadConfigFileRevision(product);
s_productMap[product->GetKey()] = product;
s_productMap[product->GetKey()] = std::shared_ptr<ProductDescriptor>(product);
}
}

Expand All @@ -269,7 +269,7 @@ namespace OpenZWave
LockGuard LG(m_MfsMutex);
if (s_bXmlLoaded)
{
map<int64, ProductDescriptor*>::iterator pit = s_productMap.begin();
map<int64, std::shared_ptr<ProductDescriptor> >::iterator pit = s_productMap.begin();
while (!s_productMap.empty())
{
pit->second->Release();
Expand Down Expand Up @@ -297,10 +297,10 @@ namespace OpenZWave
string configPath;
Options::Get()->GetOptionAsString("ConfigPath", &configPath);

map<int64, ProductDescriptor*>::iterator pit;
map<int64, std::shared_ptr<ProductDescriptor> >::iterator pit;
for (pit = s_productMap.begin(); pit != s_productMap.end(); pit++)
{
ProductDescriptor *c = pit->second;
std::shared_ptr<ProductDescriptor> c = pit->second;
if (c->GetConfigPath().size() > 0)
{
string path = configPath + c->GetConfigPath();
Expand Down Expand Up @@ -396,7 +396,7 @@ namespace OpenZWave
}
}

ProductDescriptor *ManufacturerSpecificDB::getProduct(uint16 _manufacturerId, uint16 _productType, uint16 _productId)
std::shared_ptr<ProductDescriptor> ManufacturerSpecificDB::getProduct(uint16 _manufacturerId, uint16 _productType, uint16 _productId)
{

if (!s_bXmlLoaded)
Expand All @@ -407,7 +407,7 @@ namespace OpenZWave
if (mit != s_manufacturerMap.end())
{
// Get the product
map<int64, ProductDescriptor*>::iterator pit = s_productMap.find(ProductDescriptor::GetKey(_manufacturerId, _productType, _productId));
map<int64, std::shared_ptr<ProductDescriptor> >::iterator pit = s_productMap.find(ProductDescriptor::GetKey(_manufacturerId, _productType, _productId));
if (pit != s_productMap.end())
{
return pit->second;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/ManufacturerSpecificDB.h
Expand Up @@ -156,11 +156,11 @@ namespace OpenZWave

static ManufacturerSpecificDB *s_instance;
public:
ProductDescriptor *getProduct(uint16 _manufacturerId, uint16 _productType, uint16 _productId);
std::shared_ptr<ProductDescriptor> getProduct(uint16 _manufacturerId, uint16 _productType, uint16 _productId);

private:
static map<uint16, string> s_manufacturerMap;
static map<int64, ProductDescriptor*> s_productMap;
static map<int64, std::shared_ptr<ProductDescriptor> > s_productMap;
static bool s_bXmlLoaded;

list<string> m_downloading;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Node.cpp
Expand Up @@ -3569,7 +3569,7 @@ bool Node::IsNodeReset()
// <Node::SetProductDetails>
// Assign a ProductDetails class to this node
//-----------------------------------------------------------------------------
void Node::SetProductDetails(Internal::ProductDescriptor *product)
void Node::SetProductDetails(std::shared_ptr<Internal::ProductDescriptor> product)
{
/* if there is a ProductDescriptor already assigned, remove the reference */
if (m_Product)
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Node.h
Expand Up @@ -563,7 +563,7 @@ namespace OpenZWave
// Configuration Revision Related Classes
//-----------------------------------------------------------------------------
public:
void SetProductDetails(Internal::ProductDescriptor *product);
void SetProductDetails(std::shared_ptr<Internal::ProductDescriptor> product);
/** Get a path to the config file for this device
*
* @return a path relative to the config directory for the config file. returns a empty string if a config file is not present.
Expand Down Expand Up @@ -618,7 +618,7 @@ namespace OpenZWave

private:

Internal::ProductDescriptor *m_Product;
std::shared_ptr<Internal::ProductDescriptor> m_Product;

uint32 m_fileConfigRevision;
uint32 m_loadedConfigRevision;
Expand Down
24 changes: 12 additions & 12 deletions cpp/src/NotificationCCTypes.cpp
Expand Up @@ -39,7 +39,7 @@ namespace OpenZWave
{

NotificationCCTypes *NotificationCCTypes::m_instance = NULL;
std::map<uint32, NotificationCCTypes::NotificationTypes *> NotificationCCTypes::Notifications;
std::map<uint32, std::shared_ptr<NotificationCCTypes::NotificationTypes> > NotificationCCTypes::Notifications;
uint32 NotificationCCTypes::m_revision(0);

NotificationCCTypes::NotificationCCTypes()
Expand Down Expand Up @@ -232,7 +232,7 @@ namespace OpenZWave
aep->name = str;
trim(aep->name);
if (ne->EventParams.find(aep->id) == ne->EventParams.end())
ne->EventParams[aep->id] = aep;
ne->EventParams[aep->id] = std::shared_ptr<NotificationEventParams>(aep);
else
{
Log::Write(LogLevel_Warning, "NotificationCCTypes::ReadXML: Error in %s - A AlarmEventParam with id %d already exists. Skipping ", nextElement->GetDocument()->GetUserData(), aep->id);
Expand All @@ -242,7 +242,7 @@ namespace OpenZWave
nextElement = nextElement->NextSiblingElement();
}
if (nt->Events.find(ne->id) == nt->Events.end())
nt->Events[ne->id] = ne;
nt->Events[ne->id] = std::shared_ptr<NotificationEvents>(ne);
else
{
Log::Write(LogLevel_Warning, "NotificationCCTypes::ReadXML: Error in %s - A AlarmEventElement with id %d already exists. Skipping ", AlarmEventElement->GetDocument()->GetUserData(), ne->id);
Expand All @@ -252,7 +252,7 @@ namespace OpenZWave
AlarmEventElement = AlarmEventElement->NextSiblingElement();
}
if (Notifications.find(nt->id) == Notifications.end())
Notifications[nt->id] = nt;
Notifications[nt->id] = std::shared_ptr<NotificationTypes>(nt);
else
{
Log::Write(LogLevel_Warning, "NotificationCCTypes::ReadXML: Error in %s - A AlarmTypeElement with id %d already exists. Skipping ", AlarmTypeElement->GetDocument()->GetUserData(), nt->id);
Expand Down Expand Up @@ -282,7 +282,7 @@ namespace OpenZWave
}
exit(0);
#endif

delete pDoc;
}

std::string NotificationCCTypes::GetEventParamNames(NotificationEventParamTypes type)
Expand Down Expand Up @@ -323,15 +323,15 @@ namespace OpenZWave

std::string NotificationCCTypes::GetEventForAlarmType(uint32 type, uint32 event)
{
if (const NotificationCCTypes::NotificationEvents *ne = NotificationCCTypes::GetAlarmNotificationEvents(type, event))
if (const std::shared_ptr<NotificationCCTypes::NotificationEvents> ne = NotificationCCTypes::GetAlarmNotificationEvents(type, event))
{
return ne->name;
}
Log::Write(LogLevel_Warning, "NotificationCCTypes::GetEventForAlarmType - Unknown AlarmType/Event %d/d", type, event);
return "Unknown";
}

const NotificationCCTypes::NotificationTypes* NotificationCCTypes::GetAlarmNotificationTypes(uint32 type)
const std::shared_ptr<NotificationCCTypes::NotificationTypes> NotificationCCTypes::GetAlarmNotificationTypes(uint32 type)
{
if (Notifications.find(type) != Notifications.end())
{
Expand All @@ -344,9 +344,9 @@ namespace OpenZWave
return NULL;
}

const NotificationCCTypes::NotificationEvents* NotificationCCTypes::GetAlarmNotificationEvents(uint32 type, uint32 event)
const std::shared_ptr<NotificationCCTypes::NotificationEvents> NotificationCCTypes::GetAlarmNotificationEvents(uint32 type, uint32 event)
{
if (const NotificationCCTypes::NotificationTypes *nt = GetAlarmNotificationTypes(type))
if (const std::shared_ptr<NotificationCCTypes::NotificationTypes> nt = GetAlarmNotificationTypes(type))
{
if (nt->Events.find(event) != nt->Events.end())
{
Expand All @@ -357,17 +357,17 @@ namespace OpenZWave
return NULL;
}

const std::map<uint32, NotificationCCTypes::NotificationEventParams*> NotificationCCTypes::GetAlarmNotificationEventParams(uint32 type, uint32 event)
const std::map<uint32, std::shared_ptr<NotificationCCTypes::NotificationEventParams> > NotificationCCTypes::GetAlarmNotificationEventParams(uint32 type, uint32 event)
{
if (const NotificationCCTypes::NotificationTypes *nt = GetAlarmNotificationTypes(type))
if (const std::shared_ptr<NotificationCCTypes::NotificationTypes> nt = GetAlarmNotificationTypes(type))
{
if (nt->Events.find(event) != nt->Events.end())
{
return nt->Events.at(event)->EventParams;
}
Log::Write(LogLevel_Warning, "NotificationCCTypes::GetAlarmNotificationEventParams - Unknown Alarm Event %d for Alarm Type %s (%d)", event, GetAlarmType(type).c_str(), type);
}
return std::map<uint32, NotificationCCTypes::NotificationEventParams*>();
return std::map<uint32, std::shared_ptr<NotificationCCTypes::NotificationEventParams> >();
}

bool NotificationCCTypes::Create()
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/NotificationCCTypes.h
Expand Up @@ -66,14 +66,14 @@ namespace OpenZWave
public:
uint32 id;
string name;
std::map<uint32, NotificationCCTypes::NotificationEventParams*> EventParams;
std::map<uint32, std::shared_ptr<NotificationCCTypes::NotificationEventParams> > EventParams;
};
class NotificationTypes
{
public:
uint32 id;
string name;
std::map<uint32, NotificationCCTypes::NotificationEvents *> Events;
std::map<uint32, std::shared_ptr<NotificationCCTypes::NotificationEvents> > Events;
};

//-----------------------------------------------------------------------------
Expand All @@ -89,16 +89,16 @@ namespace OpenZWave
static string GetEventParamNames(NotificationEventParamTypes);
string GetAlarmType(uint32);
string GetEventForAlarmType(uint32, uint32);
const NotificationTypes *GetAlarmNotificationTypes(uint32);
const NotificationEvents *GetAlarmNotificationEvents(uint32, uint32);
const std::map<uint32, NotificationCCTypes::NotificationEventParams*> GetAlarmNotificationEventParams(uint32, uint32);
const std::shared_ptr<NotificationCCTypes::NotificationTypes> GetAlarmNotificationTypes(uint32);
const std::shared_ptr<NotificationEvents> GetAlarmNotificationEvents(uint32, uint32);
const std::map<uint32, std::shared_ptr<NotificationCCTypes::NotificationEventParams>> GetAlarmNotificationEventParams(uint32, uint32);

//-----------------------------------------------------------------------------
// Instance Functions
//-----------------------------------------------------------------------------
private:
static NotificationCCTypes* m_instance;
static std::map<uint32, NotificationCCTypes::NotificationTypes *> Notifications;
static std::map<uint32,std::shared_ptr<NotificationCCTypes::NotificationTypes> > Notifications;
static uint32 m_revision;
};
} // namespace Internal
Expand Down

0 comments on commit eab8d30

Please sign in to comment.