- 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,6 +91,7 @@ GoosePublisher_create(CommParameters* parameters, const char* interfaceID)
void
GoosePublisher_destroy(GoosePublisher self)
{
if (self) {
if (self->ethernetSocket) {
Ethernet_destroySocket(self->ethernetSocket);
}
@ -110,6 +111,7 @@ GoosePublisher_destroy(GoosePublisher self)
GLOBAL_FREEMEM(self->buffer);
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,6 +1014,7 @@ 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);
@ -1027,6 +1028,7 @@ GooseReceiver_destroy(GooseReceiver 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,6 +40,7 @@ GooseSubscriber_create(char* goCbRef, MmsValue* dataSetValues)
{
GooseSubscriber self = (GooseSubscriber) GLOBAL_CALLOC(1, sizeof(struct sGooseSubscriber));
if (self) {
strncpy(self->goCBRef, goCbRef, 129);
self->goCBRef[129] = 0;
@ -58,6 +59,7 @@ GooseSubscriber_create(char* goCbRef, MmsValue* dataSetValues)
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)
{
if (self) {
MmsValue_delete(self->timestamp);
if (self->dataSetValuesSelfAllocated)
MmsValue_delete(self->dataSetValues);
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);
#endif
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);
#endif
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,7 +594,7 @@ IedServer_setRCBEventHandler(IedServer self, IedServer_RCBEventHandler handler,
void
IedServer_destroy(IedServer self)
{
if (self) {
/* Stop server if running */
if (self->running) {
#if (CONFIG_MMS_THREADLESS_STACK == 1)
@ -639,6 +639,7 @@ IedServer_destroy(IedServer self)
#endif /* (CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY == 1) */
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)
{
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,6 +1254,7 @@ ControlObject_handlePendingEvents(ControlObject* self)
void
ControlObject_destroy(ControlObject* self)
{
if (self) {
if (self->mmsValue)
MmsValue_delete(self->mmsValue);
@ -1284,6 +1285,7 @@ ControlObject_destroy(ControlObject* self)
#endif
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,6 +48,7 @@ LogInstance_create(LogicalNode* parentLN, const char* name)
{
LogInstance* self = (LogInstance*) GLOBAL_MALLOC(sizeof(LogInstance));
if (self) {
self->name = StringUtils_copyString(name);
self->parentLN = parentLN;
self->logStorage = NULL;
@ -57,6 +58,7 @@ LogInstance_create(LogicalNode* parentLN, const char* name)
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)
{
if (self) {
GLOBAL_FREEMEM(self->name);
GLOBAL_FREEMEM(self);
}
}
void
@ -185,6 +189,7 @@ LogControl_create(LogicalNode* parentLN, MmsMapping* mmsMapping)
{
LogControl* self = (LogControl*) GLOBAL_MALLOC(sizeof(LogControl));
if (self) {
self->enabled = false;
self->dataSet = NULL;
self->isDynamicDataSet = false;
@ -196,6 +201,7 @@ LogControl_create(LogicalNode* parentLN, MmsMapping* mmsMapping)
self->intgPd = 0;
self->nextIntegrityScan = 0;
self->logRef = NULL;
}
return self;
}

@ -274,6 +274,8 @@ MmsGooseControlBlock_create()
void
MmsGooseControlBlock_destroy(MmsGooseControlBlock self)
{
if (self) {
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_destroy(self->publisherMutex);
#endif
@ -307,6 +309,7 @@ MmsGooseControlBlock_destroy(MmsGooseControlBlock self)
MmsValue_delete(self->mmsValue);
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)
{
if (self) {
MmsValue_delete(self->mmsValue);
GLOBAL_FREEMEM(self);
}
}
static MmsSampledValueControlBlock

@ -84,6 +84,7 @@ ReportBuffer_create(int bufferSize)
static void
ReportBuffer_destroy(ReportBuffer* self)
{
if (self) {
GLOBAL_FREEMEM(self->memoryBlock);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
@ -91,12 +92,15 @@ ReportBuffer_destroy(ReportBuffer* self)
#endif
GLOBAL_FREEMEM(self);
}
}
ReportControl*
ReportControl_create(bool buffered, LogicalNode* parentLN, int reportBufferSize, IedServer iedServer)
{
ReportControl* self = (ReportControl*) GLOBAL_MALLOC(sizeof(ReportControl));
if (self) {
self->name = NULL;
self->domain = NULL;
self->parentLN = parentLN;
@ -141,6 +145,7 @@ ReportControl_create(bool buffered, LogicalNode* parentLN, int reportBufferSize,
self->server = iedServer;
self->reportBuffer = ReportBuffer_create(reportBufferSize);
}
return self;
}
@ -206,6 +211,7 @@ deleteDataSetValuesShadowBuffer(ReportControl* self)
void
ReportControl_destroy(ReportControl* self)
{
if (self) {
if (self->rcbValues != NULL )
MmsValue_delete(self->rcbValues);
@ -244,6 +250,7 @@ ReportControl_destroy(ReportControl* self)
GLOBAL_FREEMEM(self->name);
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,6 +761,9 @@ DataSetEntry_create(DataSet* dataSet, const char* variable, int index, const cha
static void
ModelNode_destroy(ModelNode* modelNode)
{
if (modelNode) {
if (modelNode->name)
GLOBAL_FREEMEM(modelNode->name);
ModelNode* currentChild = modelNode->firstChild;
@ -783,11 +786,13 @@ ModelNode_destroy(ModelNode* modelNode)
}
GLOBAL_FREEMEM(modelNode);
}
}
void
IedModel_destroy(IedModel* model)
{
if (model) {
/* delete all model nodes and dynamically created strings */
/* delete all logical devices */
@ -950,5 +955,6 @@ IedModel_destroy(IedModel* model)
GLOBAL_FREEMEM(model->name);
GLOBAL_FREEMEM(model);
}
}

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

Loading…
Cancel
Save