- added null pointer protection to some constructors/destructors

pull/375/head
Michael Zillgith 4 years ago
parent 8aa988068c
commit 398b14e65f

@ -1,7 +1,7 @@
/*
* goose_publisher.c
*
* Copyright 2013-2018 Michael Zillgith
* Copyright 2013-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -91,25 +91,27 @@ GoosePublisher_create(CommParameters* parameters, const char* interfaceID)
void
GoosePublisher_destroy(GoosePublisher self)
{
if (self->ethernetSocket) {
Ethernet_destroySocket(self->ethernetSocket);
}
if (self) {
if (self->ethernetSocket) {
Ethernet_destroySocket(self->ethernetSocket);
}
MmsValue_delete(self->timestamp);
MmsValue_delete(self->timestamp);
if (self->goID != NULL)
GLOBAL_FREEMEM(self->goID);
if (self->goID != NULL)
GLOBAL_FREEMEM(self->goID);
if (self->goCBRef != NULL)
GLOBAL_FREEMEM(self->goCBRef);
if (self->goCBRef != NULL)
GLOBAL_FREEMEM(self->goCBRef);
if (self->dataSetRef != NULL)
GLOBAL_FREEMEM(self->dataSetRef);
if (self->dataSetRef != NULL)
GLOBAL_FREEMEM(self->dataSetRef);
if (self->buffer)
GLOBAL_FREEMEM(self->buffer);
if (self->buffer)
GLOBAL_FREEMEM(self->buffer);
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}
void

@ -1,7 +1,7 @@
/*
* goose_receiver.c
*
* Copyright 2014-2017 Michael Zillgith
* Copyright 2014-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -1014,19 +1014,21 @@ GooseReceiver_stop(GooseReceiver self)
void
GooseReceiver_destroy(GooseReceiver self)
{
if (self) {
#if (CONFIG_MMS_THREADLESS_STACK == 0)
if ((self->thread != NULL) && (GooseReceiver_isRunning(self)))
GooseReceiver_stop(self);
if ((self->thread != NULL) && (GooseReceiver_isRunning(self)))
GooseReceiver_stop(self);
#endif
if (self->interfaceId != NULL)
GLOBAL_FREEMEM(self->interfaceId);
if (self->interfaceId != NULL)
GLOBAL_FREEMEM(self->interfaceId);
LinkedList_destroyDeep(self->subscriberList,
(LinkedListValueDeleteFunction) GooseSubscriber_destroy);
LinkedList_destroyDeep(self->subscriberList,
(LinkedListValueDeleteFunction) GooseSubscriber_destroy);
GLOBAL_FREEMEM(self->buffer);
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self->buffer);
GLOBAL_FREEMEM(self);
}
}
/***************************************

@ -1,7 +1,7 @@
/*
* goose_subscriber.c
*
* Copyright 2013, 2014 Michael Zillgith
* Copyright 2013-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -40,24 +40,26 @@ GooseSubscriber_create(char* goCbRef, MmsValue* dataSetValues)
{
GooseSubscriber self = (GooseSubscriber) GLOBAL_CALLOC(1, sizeof(struct sGooseSubscriber));
strncpy(self->goCBRef, goCbRef, 129);
self->goCBRef[129] = 0;
if (self) {
strncpy(self->goCBRef, goCbRef, 129);
self->goCBRef[129] = 0;
self->goCBRefLen = strlen(goCbRef);
self->timestamp = MmsValue_newUtcTime(0);
self->dataSetValues = dataSetValues;
self->goCBRefLen = strlen(goCbRef);
self->timestamp = MmsValue_newUtcTime(0);
self->dataSetValues = dataSetValues;
if (dataSetValues)
self->dataSetValuesSelfAllocated = false;
else
self->dataSetValuesSelfAllocated = true;
if (dataSetValues)
self->dataSetValuesSelfAllocated = false;
else
self->dataSetValuesSelfAllocated = true;
memset(self->dstMac, 0xFF, 6);
self->dstMacSet = false;
self->appId = -1;
self->isObserver = false;
self->vlanSet = false;
self->parseError = GOOSE_PARSE_ERROR_NO_ERROR;
memset(self->dstMac, 0xFF, 6);
self->dstMacSet = false;
self->appId = -1;
self->isObserver = false;
self->vlanSet = false;
self->parseError = GOOSE_PARSE_ERROR_NO_ERROR;
}
return self;
}
@ -96,12 +98,14 @@ GooseSubscriber_setAppId(GooseSubscriber self, uint16_t appId)
void
GooseSubscriber_destroy(GooseSubscriber self)
{
MmsValue_delete(self->timestamp);
if (self) {
MmsValue_delete(self->timestamp);
if (self->dataSetValuesSelfAllocated)
MmsValue_delete(self->dataSetValues);
if (self->dataSetValuesSelfAllocated)
MmsValue_delete(self->dataSetValues);
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}
void

@ -1,7 +1,7 @@
/*
* client_connection.c
*
* Copyright 2013, 2014, 2015 Michael Zillgith
* Copyright 2013-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -47,12 +47,14 @@ private_ClientConnection_create(void* serverConnectionHandle)
{
ClientConnection self = (ClientConnection) GLOBAL_MALLOC(sizeof(struct sClientConnection));
if (self) {
#if (CONFIG_MMS_THREADLESS_STACK != 1)
self->tasksCountMutex = Semaphore_create(1);
self->tasksCountMutex = Semaphore_create(1);
#endif
self->tasksCount = 0;
self->serverConnectionHandle = serverConnectionHandle;
self->tasksCount = 0;
self->serverConnectionHandle = serverConnectionHandle;
}
return self;
}
@ -60,11 +62,13 @@ private_ClientConnection_create(void* serverConnectionHandle)
void
private_ClientConnection_destroy(ClientConnection self)
{
if (self) {
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_destroy(self->tasksCountMutex);
Semaphore_destroy(self->tasksCountMutex);
#endif
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}
int

@ -1,7 +1,7 @@
/*
* ied_server.c
*
* Copyright 2013-2020 Michael Zillgith
* Copyright 2013-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -594,51 +594,52 @@ IedServer_setRCBEventHandler(IedServer self, IedServer_RCBEventHandler handler,
void
IedServer_destroy(IedServer self)
{
if (self) {
/* Stop server if running */
if (self->running) {
if (self->running) {
#if (CONFIG_MMS_THREADLESS_STACK == 1)
IedServer_stopThreadless(self);
IedServer_stopThreadless(self);
#else
IedServer_stop(self);
IedServer_stop(self);
#endif
}
}
#if ((CONFIG_MMS_SINGLE_THREADED == 1) && (CONFIG_MMS_THREADLESS_STACK == 0))
if (self->serverThread)
Thread_destroy(self->serverThread);
if (self->serverThread)
Thread_destroy(self->serverThread);
#endif
MmsServer_destroy(self->mmsServer);
MmsServer_destroy(self->mmsServer);
if (self->localIpAddress != NULL)
GLOBAL_FREEMEM(self->localIpAddress);
if (self->localIpAddress != NULL)
GLOBAL_FREEMEM(self->localIpAddress);
if (self->mmsMapping)
MmsMapping_destroy(self->mmsMapping);
if (self->mmsMapping)
MmsMapping_destroy(self->mmsMapping);
LinkedList_destroyDeep(self->clientConnections, (LinkedListValueDeleteFunction) private_ClientConnection_destroy);
LinkedList_destroyDeep(self->clientConnections, (LinkedListValueDeleteFunction) private_ClientConnection_destroy);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_destroy(self->dataModelLock);
Semaphore_destroy(self->clientConnectionsLock);
Semaphore_destroy(self->dataModelLock);
Semaphore_destroy(self->clientConnectionsLock);
#endif
#if (CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY == 1)
if (self->vendorName)
GLOBAL_FREEMEM(self->vendorName);
if (self->vendorName)
GLOBAL_FREEMEM(self->vendorName);
if (self->modelName)
GLOBAL_FREEMEM(self->modelName);
if (self->modelName)
GLOBAL_FREEMEM(self->modelName);
if (self->revision)
GLOBAL_FREEMEM(self->revision);
if (self->revision)
GLOBAL_FREEMEM(self->revision);
#endif /* (CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY == 1) */
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}
void

@ -1,7 +1,7 @@
/*
* ied_server_config.c
*
* Copyright 2018-2020 Michael Zillgith
* Copyright 2018-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -65,8 +65,10 @@ IedServerConfig_create()
void
IedServerConfig_destroy(IedServerConfig self)
{
GLOBAL_FREEMEM(self->fileServiceBasepath);
GLOBAL_FREEMEM(self);
if (self) {
GLOBAL_FREEMEM(self->fileServiceBasepath);
GLOBAL_FREEMEM(self);
}
}
void

@ -1,7 +1,7 @@
/*
* control.c
*
* Copyright 2013-2021 Michael Zillgith
* Copyright 2013-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -1254,36 +1254,38 @@ ControlObject_handlePendingEvents(ControlObject* self)
void
ControlObject_destroy(ControlObject* self)
{
if (self->mmsValue)
MmsValue_delete(self->mmsValue);
if (self) {
if (self->mmsValue)
MmsValue_delete(self->mmsValue);
if (self->error)
MmsValue_delete(self->error);
if (self->error)
MmsValue_delete(self->error);
if (self->addCause)
MmsValue_delete(self->addCause);
if (self->addCause)
MmsValue_delete(self->addCause);
if (self->ctlVal)
MmsValue_delete(self->ctlVal);
if (self->ctlVal)
MmsValue_delete(self->ctlVal);
if (self->ctlNum)
MmsValue_delete(self->ctlNum);
if (self->ctlNum)
MmsValue_delete(self->ctlNum);
if (self->origin)
MmsValue_delete(self->origin);
if (self->origin)
MmsValue_delete(self->origin);
if (self->name)
GLOBAL_FREEMEM(self->name);
if (self->name)
GLOBAL_FREEMEM(self->name);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
if (self->stateLock)
Semaphore_destroy(self->stateLock);
if (self->stateLock)
Semaphore_destroy(self->stateLock);
if (self->pendingEventsLock)
Semaphore_destroy(self->pendingEventsLock);
if (self->pendingEventsLock)
Semaphore_destroy(self->pendingEventsLock);
#endif
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}
char*

@ -1,7 +1,7 @@
/*
* logging.c
*
* Copyright 2016 Michael Zillgith
* Copyright 2016-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -48,15 +48,17 @@ LogInstance_create(LogicalNode* parentLN, const char* name)
{
LogInstance* self = (LogInstance*) GLOBAL_MALLOC(sizeof(LogInstance));
self->name = StringUtils_copyString(name);
self->parentLN = parentLN;
self->logStorage = NULL;
self->locked = false;
if (self) {
self->name = StringUtils_copyString(name);
self->parentLN = parentLN;
self->logStorage = NULL;
self->locked = false;
self->oldEntryId = 0;
self->oldEntryTime = 0;
self->newEntryId = 0;
self->newEntryTime = 0;
self->oldEntryId = 0;
self->oldEntryTime = 0;
self->newEntryId = 0;
self->newEntryTime = 0;
}
return self;
}
@ -64,8 +66,10 @@ LogInstance_create(LogicalNode* parentLN, const char* name)
void
LogInstance_destroy(LogInstance* self)
{
GLOBAL_FREEMEM(self->name);
GLOBAL_FREEMEM(self);
if (self) {
GLOBAL_FREEMEM(self->name);
GLOBAL_FREEMEM(self);
}
}
void
@ -185,17 +189,19 @@ LogControl_create(LogicalNode* parentLN, MmsMapping* mmsMapping)
{
LogControl* self = (LogControl*) GLOBAL_MALLOC(sizeof(LogControl));
self->enabled = false;
self->dataSet = NULL;
self->isDynamicDataSet = false;
self->triggerOps = 0;
self->logicalNode = parentLN;
self->mmsMapping = mmsMapping;
self->dataSetRef = NULL;
self->logInstance = NULL;
self->intgPd = 0;
self->nextIntegrityScan = 0;
self->logRef = NULL;
if (self) {
self->enabled = false;
self->dataSet = NULL;
self->isDynamicDataSet = false;
self->triggerOps = 0;
self->logicalNode = parentLN;
self->mmsMapping = mmsMapping;
self->dataSetRef = NULL;
self->logInstance = NULL;
self->intgPd = 0;
self->nextIntegrityScan = 0;
self->logRef = NULL;
}
return self;
}

@ -274,39 +274,42 @@ MmsGooseControlBlock_create()
void
MmsGooseControlBlock_destroy(MmsGooseControlBlock self)
{
if (self) {
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_destroy(self->publisherMutex);
Semaphore_destroy(self->publisherMutex);
#endif
if (self->publisher != NULL)
GoosePublisher_destroy(self->publisher);
GoosePublisher_destroy(self->publisher);
if (self->dataSetValues != NULL)
LinkedList_destroyStatic(self->dataSetValues);
if (self->dataSetValues != NULL)
LinkedList_destroyStatic(self->dataSetValues);
if (self->goCBRef != NULL)
GLOBAL_FREEMEM(self->goCBRef);
if (self->goCBRef != NULL)
GLOBAL_FREEMEM(self->goCBRef);
if (self->goId != NULL)
GLOBAL_FREEMEM(self->goId);
if (self->goId != NULL)
GLOBAL_FREEMEM(self->goId);
if (self->dataSetRef != NULL)
GLOBAL_FREEMEM(self->dataSetRef);
if (self->dataSetRef != NULL)
GLOBAL_FREEMEM(self->dataSetRef);
if (self->dataSet != NULL) {
if (self->isDynamicDataSet) {
MmsMapping_freeDynamicallyCreatedDataSet(self->dataSet);
self->isDynamicDataSet = false;
self->dataSet = NULL;
if (self->dataSet != NULL) {
if (self->isDynamicDataSet) {
MmsMapping_freeDynamicallyCreatedDataSet(self->dataSet);
self->isDynamicDataSet = false;
self->dataSet = NULL;
}
}
}
if (self->gooseInterfaceId != NULL)
GLOBAL_FREEMEM(self->gooseInterfaceId);
if (self->gooseInterfaceId != NULL)
GLOBAL_FREEMEM(self->gooseInterfaceId);
MmsValue_delete(self->mmsValue);
MmsValue_delete(self->mmsValue);
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}
void

@ -1,7 +1,7 @@
/*
* mms_sv.c
*
* Copyright 2015 Michael Zillgith
* Copyright 2015-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -67,9 +67,11 @@ MmsSampledValueControlBlock_create()
void
MmsSampledValueControlBlock_destroy(MmsSampledValueControlBlock self)
{
MmsValue_delete(self->mmsValue);
if (self) {
MmsValue_delete(self->mmsValue);
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}
static MmsSampledValueControlBlock

@ -84,63 +84,68 @@ ReportBuffer_create(int bufferSize)
static void
ReportBuffer_destroy(ReportBuffer* self)
{
GLOBAL_FREEMEM(self->memoryBlock);
if (self) {
GLOBAL_FREEMEM(self->memoryBlock);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_destroy(self->lock);
Semaphore_destroy(self->lock);
#endif
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}
ReportControl*
ReportControl_create(bool buffered, LogicalNode* parentLN, int reportBufferSize, IedServer iedServer)
{
ReportControl* self = (ReportControl*) GLOBAL_MALLOC(sizeof(ReportControl));
self->name = NULL;
self->domain = NULL;
self->parentLN = parentLN;
self->rcbValues = NULL;
if (self) {
self->name = NULL;
self->domain = NULL;
self->parentLN = parentLN;
self->rcbValues = NULL;
#if (CONFIG_MMS_THREADLESS_STACK != 1)
self->rcbValuesLock = Semaphore_create(1);
self->rcbValuesLock = Semaphore_create(1);
#endif
self->subSeqVal = MmsValue_newUnsigned(16);
self->segmented = false;
self->startIndexForNextSegment = 0;
self->enabled = false;
self->reserved = false;
self->buffered = buffered;
self->isBuffering = false;
self->isResync = false;
self->gi = false;
self->inclusionField = NULL;
self->dataSet = NULL;
self->isDynamicDataSet = false;
self->clientConnection = NULL;
self->intgPd = 0;
self->sqNum = 0;
self->nextIntgReportTime = 0;
self->inclusionFlags = NULL;
self->triggered = false;
self->timeOfEntry = NULL;
self->reservationTimeout = 0;
self->triggerOps = 0;
self->hasOwner = false;
self->subSeqVal = MmsValue_newUnsigned(16);
self->segmented = false;
self->startIndexForNextSegment = 0;
self->enabled = false;
self->reserved = false;
self->buffered = buffered;
self->isBuffering = false;
self->isResync = false;
self->gi = false;
self->inclusionField = NULL;
self->dataSet = NULL;
self->isDynamicDataSet = false;
self->clientConnection = NULL;
self->intgPd = 0;
self->sqNum = 0;
self->nextIntgReportTime = 0;
self->inclusionFlags = NULL;
self->triggered = false;
self->timeOfEntry = NULL;
self->reservationTimeout = 0;
self->triggerOps = 0;
self->hasOwner = false;
#if (CONFIG_MMS_THREADLESS_STACK != 1)
self->createNotificationsMutex = Semaphore_create(1);
self->createNotificationsMutex = Semaphore_create(1);
#endif
self->bufferedDataSetValues = NULL;
self->valueReferences = NULL;
self->lastEntryId = 0;
self->resvTms = 0;
self->bufferedDataSetValues = NULL;
self->valueReferences = NULL;
self->lastEntryId = 0;
self->resvTms = 0;
self->server = iedServer;
self->server = iedServer;
self->reportBuffer = ReportBuffer_create(reportBufferSize);
self->reportBuffer = ReportBuffer_create(reportBufferSize);
}
return self;
}
@ -206,44 +211,46 @@ deleteDataSetValuesShadowBuffer(ReportControl* self)
void
ReportControl_destroy(ReportControl* self)
{
if (self->rcbValues != NULL )
MmsValue_delete(self->rcbValues);
if (self) {
if (self->rcbValues != NULL )
MmsValue_delete(self->rcbValues);
if (self->inclusionFlags != NULL)
GLOBAL_FREEMEM(self->inclusionFlags);
if (self->inclusionFlags != NULL)
GLOBAL_FREEMEM(self->inclusionFlags);
if (self->inclusionField != NULL)
MmsValue_delete(self->inclusionField);
if (self->inclusionField != NULL)
MmsValue_delete(self->inclusionField);
if (self->buffered == false)
MmsValue_delete(self->timeOfEntry);
if (self->buffered == false)
MmsValue_delete(self->timeOfEntry);
MmsValue_delete(self->subSeqVal);
MmsValue_delete(self->subSeqVal);
deleteDataSetValuesShadowBuffer(self);
deleteDataSetValuesShadowBuffer(self);
if (self->isDynamicDataSet) {
if (self->dataSet != NULL) {
MmsMapping_freeDynamicallyCreatedDataSet(self->dataSet);
self->isDynamicDataSet = false;
self->dataSet = NULL;
if (self->isDynamicDataSet) {
if (self->dataSet != NULL) {
MmsMapping_freeDynamicallyCreatedDataSet(self->dataSet);
self->isDynamicDataSet = false;
self->dataSet = NULL;
}
}
}
/* restore original sibling of ReportControlBlock */
self->rcb->sibling = self->sibling;
self->rcb->trgOps &= ~(64); /* clear runtime mode flag */
/* restore original sibling of ReportControlBlock */
self->rcb->sibling = self->sibling;
self->rcb->trgOps &= ~(64); /* clear runtime mode flag */
ReportBuffer_destroy(self->reportBuffer);
ReportBuffer_destroy(self->reportBuffer);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_destroy(self->createNotificationsMutex);
Semaphore_destroy(self->rcbValuesLock);
Semaphore_destroy(self->createNotificationsMutex);
Semaphore_destroy(self->rcbValuesLock);
#endif
GLOBAL_FREEMEM(self->name);
GLOBAL_FREEMEM(self->name);
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}
MmsValue*

@ -1,7 +1,7 @@
/*
* dynamic_model.c
*
* Copyright 2014-2016 Michael Zillgith
* Copyright 2014-2022 Michael Zillgith
*
* This file is part of libIEC61850.
*
@ -761,194 +761,200 @@ DataSetEntry_create(DataSet* dataSet, const char* variable, int index, const cha
static void
ModelNode_destroy(ModelNode* modelNode)
{
GLOBAL_FREEMEM(modelNode->name);
if (modelNode) {
ModelNode* currentChild = modelNode->firstChild;
if (modelNode->name)
GLOBAL_FREEMEM(modelNode->name);
while (currentChild != NULL) {
ModelNode* nextChild = currentChild->sibling;
ModelNode* currentChild = modelNode->firstChild;
ModelNode_destroy(currentChild);
while (currentChild != NULL) {
ModelNode* nextChild = currentChild->sibling;
currentChild = nextChild;
}
ModelNode_destroy(currentChild);
currentChild = nextChild;
}
if (modelNode->modelType == DataAttributeModelType) {
DataAttribute* dataAttribute = (DataAttribute*) modelNode;
if (modelNode->modelType == DataAttributeModelType) {
DataAttribute* dataAttribute = (DataAttribute*) modelNode;
if (dataAttribute->mmsValue != NULL) {
MmsValue_delete(dataAttribute->mmsValue);
dataAttribute->mmsValue = NULL;
if (dataAttribute->mmsValue != NULL) {
MmsValue_delete(dataAttribute->mmsValue);
dataAttribute->mmsValue = NULL;
}
}
}
GLOBAL_FREEMEM(modelNode);
GLOBAL_FREEMEM(modelNode);
}
}
void
IedModel_destroy(IedModel* model)
{
/* delete all model nodes and dynamically created strings */
if (model) {
/* delete all model nodes and dynamically created strings */
/* delete all logical devices */
/* delete all logical devices */
LogicalDevice* ld = model->firstChild;
LogicalDevice* ld = model->firstChild;
while (ld != NULL) {
GLOBAL_FREEMEM (ld->name);
while (ld != NULL) {
GLOBAL_FREEMEM (ld->name);
LogicalNode* ln = (LogicalNode*) ld->firstChild;
LogicalNode* ln = (LogicalNode*) ld->firstChild;
while (ln != NULL) {
GLOBAL_FREEMEM(ln->name);
while (ln != NULL) {
GLOBAL_FREEMEM(ln->name);
/* delete all data objects */
/* delete all data objects */
DataObject* currentDataObject = (DataObject*) ln->firstChild;
DataObject* currentDataObject = (DataObject*) ln->firstChild;
while (currentDataObject != NULL) {
DataObject* nextDataObject = (DataObject*) currentDataObject->sibling;
while (currentDataObject != NULL) {
DataObject* nextDataObject = (DataObject*) currentDataObject->sibling;
ModelNode_destroy((ModelNode*) currentDataObject);
ModelNode_destroy((ModelNode*) currentDataObject);
currentDataObject = nextDataObject;
}
currentDataObject = nextDataObject;
}
LogicalNode* currentLn = ln;
ln = (LogicalNode*) ln->sibling;
LogicalNode* currentLn = ln;
ln = (LogicalNode*) ln->sibling;
GLOBAL_FREEMEM(currentLn);
}
GLOBAL_FREEMEM(currentLn);
}
LogicalDevice* currentLd = ld;
ld = (LogicalDevice*) ld->sibling;
LogicalDevice* currentLd = ld;
ld = (LogicalDevice*) ld->sibling;
GLOBAL_FREEMEM(currentLd);
}
GLOBAL_FREEMEM(currentLd);
}
/* delete all data sets */
/* delete all data sets */
DataSet* dataSet = model->dataSets;
DataSet* dataSet = model->dataSets;
while (dataSet != NULL) {
DataSet* nextDataSet = dataSet->sibling;
while (dataSet != NULL) {
DataSet* nextDataSet = dataSet->sibling;
GLOBAL_FREEMEM(dataSet->name);
GLOBAL_FREEMEM(dataSet->name);
DataSetEntry* dse = dataSet->fcdas;
DataSetEntry* dse = dataSet->fcdas;
while (dse != NULL) {
DataSetEntry* nextDse = dse->sibling;
while (dse != NULL) {
DataSetEntry* nextDse = dse->sibling;
if (dse->componentName != NULL)
GLOBAL_FREEMEM(dse->componentName);
if (dse->componentName != NULL)
GLOBAL_FREEMEM(dse->componentName);
GLOBAL_FREEMEM(dse->variableName);
GLOBAL_FREEMEM(dse->variableName);
if (dse->isLDNameDynamicallyAllocated)
GLOBAL_FREEMEM(dse->logicalDeviceName);
if (dse->isLDNameDynamicallyAllocated)
GLOBAL_FREEMEM(dse->logicalDeviceName);
GLOBAL_FREEMEM(dse);
GLOBAL_FREEMEM(dse);
dse = nextDse;
}
dse = nextDse;
}
GLOBAL_FREEMEM(dataSet);
GLOBAL_FREEMEM(dataSet);
dataSet = nextDataSet;
}
dataSet = nextDataSet;
}
/* delete all RCBs */
/* delete all RCBs */
ReportControlBlock* rcb = model->rcbs;
ReportControlBlock* rcb = model->rcbs;
while (rcb != NULL) {
ReportControlBlock* nextRcb = rcb->sibling;
while (rcb != NULL) {
ReportControlBlock* nextRcb = rcb->sibling;
GLOBAL_FREEMEM(rcb->name);
GLOBAL_FREEMEM(rcb->name);
if (rcb->rptId)
GLOBAL_FREEMEM(rcb->rptId);
if (rcb->rptId)
GLOBAL_FREEMEM(rcb->rptId);
if (rcb->dataSetName)
GLOBAL_FREEMEM(rcb->dataSetName);
if (rcb->dataSetName)
GLOBAL_FREEMEM(rcb->dataSetName);
GLOBAL_FREEMEM(rcb);
GLOBAL_FREEMEM(rcb);
rcb = nextRcb;
}
rcb = nextRcb;
}
/* delete all GoCBs */
/* delete all GoCBs */
GSEControlBlock* gcb = model->gseCBs;
GSEControlBlock* gcb = model->gseCBs;
while (gcb != NULL) {
GSEControlBlock* nextGcb = gcb->sibling;
while (gcb != NULL) {
GSEControlBlock* nextGcb = gcb->sibling;
GLOBAL_FREEMEM(gcb->name);
GLOBAL_FREEMEM(gcb->appId);
GLOBAL_FREEMEM(gcb->dataSetName);
GLOBAL_FREEMEM(gcb->name);
GLOBAL_FREEMEM(gcb->appId);
GLOBAL_FREEMEM(gcb->dataSetName);
if (gcb->address)
GLOBAL_FREEMEM(gcb->address);
if (gcb->address)
GLOBAL_FREEMEM(gcb->address);
GLOBAL_FREEMEM(gcb);
GLOBAL_FREEMEM(gcb);
gcb = nextGcb;
}
gcb = nextGcb;
}
/* delete setting controls */
/* delete setting controls */
SettingGroupControlBlock* sgcb = model->sgcbs;
SettingGroupControlBlock* sgcb = model->sgcbs;
while (sgcb != NULL) {
SettingGroupControlBlock* nextSgcb = sgcb->sibling;
while (sgcb != NULL) {
SettingGroupControlBlock* nextSgcb = sgcb->sibling;
GLOBAL_FREEMEM(sgcb);
GLOBAL_FREEMEM(sgcb);
sgcb = nextSgcb;
}
sgcb = nextSgcb;
}
/* delete all LCBs */
LogControlBlock* lcb = model->lcbs;
/* delete all LCBs */
LogControlBlock* lcb = model->lcbs;
while (lcb != NULL) {
LogControlBlock* nextLcb = lcb->sibling;
while (lcb != NULL) {
LogControlBlock* nextLcb = lcb->sibling;
if (lcb->name)
GLOBAL_FREEMEM(lcb->name);
if (lcb->name)
GLOBAL_FREEMEM(lcb->name);
if (lcb->dataSetName)
GLOBAL_FREEMEM(lcb->dataSetName);
if (lcb->dataSetName)
GLOBAL_FREEMEM(lcb->dataSetName);
if (lcb->logRef)
GLOBAL_FREEMEM(lcb->logRef);
if (lcb->logRef)
GLOBAL_FREEMEM(lcb->logRef);
GLOBAL_FREEMEM(lcb);
GLOBAL_FREEMEM(lcb);
lcb = nextLcb;
}
lcb = nextLcb;
}
/* delete all LOGs */
Log* log = model->logs;
/* delete all LOGs */
Log* log = model->logs;
while (log != NULL) {
Log* nextLog = log->sibling;
while (log != NULL) {
Log* nextLog = log->sibling;
if (log->name)
GLOBAL_FREEMEM(log->name);
if (log->name)
GLOBAL_FREEMEM(log->name);
GLOBAL_FREEMEM(log);
GLOBAL_FREEMEM(log);
log = nextLog;
}
log = nextLog;
}
/* delete generic model parts */
/* delete generic model parts */
if (model->name)
GLOBAL_FREEMEM(model->name);
if (model->name)
GLOBAL_FREEMEM(model->name);
GLOBAL_FREEMEM(model);
GLOBAL_FREEMEM(model);
}
}

@ -483,23 +483,25 @@ SVPublisher_publish(SVPublisher self)
void
SVPublisher_destroy(SVPublisher self)
{
if (self->ethernetSocket)
Ethernet_destroySocket(self->ethernetSocket);
if (self) {
if (self->ethernetSocket)
Ethernet_destroySocket(self->ethernetSocket);
if (self->buffer)
GLOBAL_FREEMEM(self->buffer);
if (self->buffer)
GLOBAL_FREEMEM(self->buffer);
SVPublisher_ASDU asdu = self->asduList;
SVPublisher_ASDU asdu = self->asduList;
while (asdu) {
SVPublisher_ASDU nextAsdu = asdu->_next;
while (asdu) {
SVPublisher_ASDU nextAsdu = asdu->_next;
GLOBAL_FREEMEM(asdu);
GLOBAL_FREEMEM(asdu);
asdu = nextAsdu;
}
asdu = nextAsdu;
}
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
}

Loading…
Cancel
Save