- 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 * goose_publisher.c
* *
* Copyright 2013-2018 Michael Zillgith * Copyright 2013-2022 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -91,6 +91,7 @@ GoosePublisher_create(CommParameters* parameters, const char* interfaceID)
void void
GoosePublisher_destroy(GoosePublisher self) GoosePublisher_destroy(GoosePublisher self)
{ {
if (self) {
if (self->ethernetSocket) { if (self->ethernetSocket) {
Ethernet_destroySocket(self->ethernetSocket); Ethernet_destroySocket(self->ethernetSocket);
} }
@ -111,6 +112,7 @@ GoosePublisher_destroy(GoosePublisher self)
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
void void
GoosePublisher_setGoID(GoosePublisher self, char* goID) GoosePublisher_setGoID(GoosePublisher self, char* goID)

@ -1,7 +1,7 @@
/* /*
* goose_receiver.c * goose_receiver.c
* *
* Copyright 2014-2017 Michael Zillgith * Copyright 2014-2022 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -1014,6 +1014,7 @@ GooseReceiver_stop(GooseReceiver self)
void void
GooseReceiver_destroy(GooseReceiver self) GooseReceiver_destroy(GooseReceiver self)
{ {
if (self) {
#if (CONFIG_MMS_THREADLESS_STACK == 0) #if (CONFIG_MMS_THREADLESS_STACK == 0)
if ((self->thread != NULL) && (GooseReceiver_isRunning(self))) if ((self->thread != NULL) && (GooseReceiver_isRunning(self)))
GooseReceiver_stop(self); GooseReceiver_stop(self);
@ -1028,6 +1029,7 @@ GooseReceiver_destroy(GooseReceiver self)
GLOBAL_FREEMEM(self->buffer); GLOBAL_FREEMEM(self->buffer);
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
/*************************************** /***************************************
* Functions for non-threaded operation * Functions for non-threaded operation

@ -1,7 +1,7 @@
/* /*
* goose_subscriber.c * goose_subscriber.c
* *
* Copyright 2013, 2014 Michael Zillgith * Copyright 2013-2022 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -40,6 +40,7 @@ GooseSubscriber_create(char* goCbRef, MmsValue* dataSetValues)
{ {
GooseSubscriber self = (GooseSubscriber) GLOBAL_CALLOC(1, sizeof(struct sGooseSubscriber)); GooseSubscriber self = (GooseSubscriber) GLOBAL_CALLOC(1, sizeof(struct sGooseSubscriber));
if (self) {
strncpy(self->goCBRef, goCbRef, 129); strncpy(self->goCBRef, goCbRef, 129);
self->goCBRef[129] = 0; self->goCBRef[129] = 0;
@ -58,6 +59,7 @@ GooseSubscriber_create(char* goCbRef, MmsValue* dataSetValues)
self->isObserver = false; self->isObserver = false;
self->vlanSet = false; self->vlanSet = false;
self->parseError = GOOSE_PARSE_ERROR_NO_ERROR; self->parseError = GOOSE_PARSE_ERROR_NO_ERROR;
}
return self; return self;
} }
@ -96,6 +98,7 @@ GooseSubscriber_setAppId(GooseSubscriber self, uint16_t appId)
void void
GooseSubscriber_destroy(GooseSubscriber self) GooseSubscriber_destroy(GooseSubscriber self)
{ {
if (self) {
MmsValue_delete(self->timestamp); MmsValue_delete(self->timestamp);
if (self->dataSetValuesSelfAllocated) if (self->dataSetValuesSelfAllocated)
@ -103,6 +106,7 @@ GooseSubscriber_destroy(GooseSubscriber self)
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
void void
GooseSubscriber_setListener(GooseSubscriber self, GooseListener listener, void* parameter) GooseSubscriber_setListener(GooseSubscriber self, GooseListener listener, void* parameter)

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

@ -1,7 +1,7 @@
/* /*
* ied_server.c * ied_server.c
* *
* Copyright 2013-2020 Michael Zillgith * Copyright 2013-2022 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -594,7 +594,7 @@ IedServer_setRCBEventHandler(IedServer self, IedServer_RCBEventHandler handler,
void void
IedServer_destroy(IedServer self) IedServer_destroy(IedServer self)
{ {
if (self) {
/* Stop server if running */ /* Stop server if running */
if (self->running) { if (self->running) {
#if (CONFIG_MMS_THREADLESS_STACK == 1) #if (CONFIG_MMS_THREADLESS_STACK == 1)
@ -640,6 +640,7 @@ IedServer_destroy(IedServer self)
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
void void
IedServer_setAuthenticator(IedServer self, AcseAuthenticator authenticator, void* authenticatorParameter) IedServer_setAuthenticator(IedServer self, AcseAuthenticator authenticator, void* authenticatorParameter)

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

@ -1,7 +1,7 @@
/* /*
* control.c * control.c
* *
* Copyright 2013-2021 Michael Zillgith * Copyright 2013-2022 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -1254,6 +1254,7 @@ ControlObject_handlePendingEvents(ControlObject* self)
void void
ControlObject_destroy(ControlObject* self) ControlObject_destroy(ControlObject* self)
{ {
if (self) {
if (self->mmsValue) if (self->mmsValue)
MmsValue_delete(self->mmsValue); MmsValue_delete(self->mmsValue);
@ -1285,6 +1286,7 @@ ControlObject_destroy(ControlObject* self)
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
char* char*
ControlObject_getName(ControlObject* self) ControlObject_getName(ControlObject* self)

@ -1,7 +1,7 @@
/* /*
* logging.c * logging.c
* *
* Copyright 2016 Michael Zillgith * Copyright 2016-2022 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -48,6 +48,7 @@ LogInstance_create(LogicalNode* parentLN, const char* name)
{ {
LogInstance* self = (LogInstance*) GLOBAL_MALLOC(sizeof(LogInstance)); LogInstance* self = (LogInstance*) GLOBAL_MALLOC(sizeof(LogInstance));
if (self) {
self->name = StringUtils_copyString(name); self->name = StringUtils_copyString(name);
self->parentLN = parentLN; self->parentLN = parentLN;
self->logStorage = NULL; self->logStorage = NULL;
@ -57,6 +58,7 @@ LogInstance_create(LogicalNode* parentLN, const char* name)
self->oldEntryTime = 0; self->oldEntryTime = 0;
self->newEntryId = 0; self->newEntryId = 0;
self->newEntryTime = 0; self->newEntryTime = 0;
}
return self; return self;
} }
@ -64,9 +66,11 @@ LogInstance_create(LogicalNode* parentLN, const char* name)
void void
LogInstance_destroy(LogInstance* self) LogInstance_destroy(LogInstance* self)
{ {
if (self) {
GLOBAL_FREEMEM(self->name); GLOBAL_FREEMEM(self->name);
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
void void
LogInstance_logSingleData(LogInstance* self, const char* dataRef, MmsValue* value, uint8_t flag) LogInstance_logSingleData(LogInstance* self, const char* dataRef, MmsValue* value, uint8_t flag)
@ -185,6 +189,7 @@ LogControl_create(LogicalNode* parentLN, MmsMapping* mmsMapping)
{ {
LogControl* self = (LogControl*) GLOBAL_MALLOC(sizeof(LogControl)); LogControl* self = (LogControl*) GLOBAL_MALLOC(sizeof(LogControl));
if (self) {
self->enabled = false; self->enabled = false;
self->dataSet = NULL; self->dataSet = NULL;
self->isDynamicDataSet = false; self->isDynamicDataSet = false;
@ -196,6 +201,7 @@ LogControl_create(LogicalNode* parentLN, MmsMapping* mmsMapping)
self->intgPd = 0; self->intgPd = 0;
self->nextIntegrityScan = 0; self->nextIntegrityScan = 0;
self->logRef = NULL; self->logRef = NULL;
}
return self; return self;
} }

@ -274,6 +274,8 @@ MmsGooseControlBlock_create()
void void
MmsGooseControlBlock_destroy(MmsGooseControlBlock self) MmsGooseControlBlock_destroy(MmsGooseControlBlock self)
{ {
if (self) {
#if (CONFIG_MMS_THREADLESS_STACK != 1) #if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_destroy(self->publisherMutex); Semaphore_destroy(self->publisherMutex);
#endif #endif
@ -308,6 +310,7 @@ MmsGooseControlBlock_destroy(MmsGooseControlBlock self)
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
void void
MmsGooseControlBlock_useGooseVlanTag(MmsGooseControlBlock self, bool useVlanTag) MmsGooseControlBlock_useGooseVlanTag(MmsGooseControlBlock self, bool useVlanTag)

@ -1,7 +1,7 @@
/* /*
* mms_sv.c * mms_sv.c
* *
* Copyright 2015 Michael Zillgith * Copyright 2015-2022 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -67,10 +67,12 @@ MmsSampledValueControlBlock_create()
void void
MmsSampledValueControlBlock_destroy(MmsSampledValueControlBlock self) MmsSampledValueControlBlock_destroy(MmsSampledValueControlBlock self)
{ {
if (self) {
MmsValue_delete(self->mmsValue); MmsValue_delete(self->mmsValue);
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
static MmsSampledValueControlBlock static MmsSampledValueControlBlock
lookupSVCB(MmsMapping* self, MmsDomain* domain, char* lnName, char* objectName) lookupSVCB(MmsMapping* self, MmsDomain* domain, char* lnName, char* objectName)

@ -84,6 +84,7 @@ ReportBuffer_create(int bufferSize)
static void static void
ReportBuffer_destroy(ReportBuffer* self) ReportBuffer_destroy(ReportBuffer* self)
{ {
if (self) {
GLOBAL_FREEMEM(self->memoryBlock); GLOBAL_FREEMEM(self->memoryBlock);
#if (CONFIG_MMS_THREADLESS_STACK != 1) #if (CONFIG_MMS_THREADLESS_STACK != 1)
@ -92,11 +93,14 @@ ReportBuffer_destroy(ReportBuffer* self)
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
ReportControl* ReportControl*
ReportControl_create(bool buffered, LogicalNode* parentLN, int reportBufferSize, IedServer iedServer) ReportControl_create(bool buffered, LogicalNode* parentLN, int reportBufferSize, IedServer iedServer)
{ {
ReportControl* self = (ReportControl*) GLOBAL_MALLOC(sizeof(ReportControl)); ReportControl* self = (ReportControl*) GLOBAL_MALLOC(sizeof(ReportControl));
if (self) {
self->name = NULL; self->name = NULL;
self->domain = NULL; self->domain = NULL;
self->parentLN = parentLN; self->parentLN = parentLN;
@ -141,6 +145,7 @@ ReportControl_create(bool buffered, LogicalNode* parentLN, int reportBufferSize,
self->server = iedServer; self->server = iedServer;
self->reportBuffer = ReportBuffer_create(reportBufferSize); self->reportBuffer = ReportBuffer_create(reportBufferSize);
}
return self; return self;
} }
@ -206,6 +211,7 @@ deleteDataSetValuesShadowBuffer(ReportControl* self)
void void
ReportControl_destroy(ReportControl* self) ReportControl_destroy(ReportControl* self)
{ {
if (self) {
if (self->rcbValues != NULL ) if (self->rcbValues != NULL )
MmsValue_delete(self->rcbValues); MmsValue_delete(self->rcbValues);
@ -245,6 +251,7 @@ ReportControl_destroy(ReportControl* self)
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
MmsValue* MmsValue*
ReportControl_getRCBValue(ReportControl* rc, char* elementName) ReportControl_getRCBValue(ReportControl* rc, char* elementName)

@ -1,7 +1,7 @@
/* /*
* dynamic_model.c * dynamic_model.c
* *
* Copyright 2014-2016 Michael Zillgith * Copyright 2014-2022 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -761,6 +761,9 @@ DataSetEntry_create(DataSet* dataSet, const char* variable, int index, const cha
static void static void
ModelNode_destroy(ModelNode* modelNode) ModelNode_destroy(ModelNode* modelNode)
{ {
if (modelNode) {
if (modelNode->name)
GLOBAL_FREEMEM(modelNode->name); GLOBAL_FREEMEM(modelNode->name);
ModelNode* currentChild = modelNode->firstChild; ModelNode* currentChild = modelNode->firstChild;
@ -784,10 +787,12 @@ ModelNode_destroy(ModelNode* modelNode)
GLOBAL_FREEMEM(modelNode); GLOBAL_FREEMEM(modelNode);
} }
}
void void
IedModel_destroy(IedModel* model) IedModel_destroy(IedModel* model)
{ {
if (model) {
/* delete all model nodes and dynamically created strings */ /* delete all model nodes and dynamically created strings */
/* delete all logical devices */ /* delete all logical devices */
@ -951,4 +956,5 @@ IedModel_destroy(IedModel* model)
GLOBAL_FREEMEM(model); GLOBAL_FREEMEM(model);
} }
}

@ -483,6 +483,7 @@ SVPublisher_publish(SVPublisher self)
void void
SVPublisher_destroy(SVPublisher self) SVPublisher_destroy(SVPublisher self)
{ {
if (self) {
if (self->ethernetSocket) if (self->ethernetSocket)
Ethernet_destroySocket(self->ethernetSocket); Ethernet_destroySocket(self->ethernetSocket);
@ -501,6 +502,7 @@ SVPublisher_destroy(SVPublisher self)
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }
}
void void

Loading…
Cancel
Save