Skip to content

Commit

Permalink
Memory management improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmichalek committed Oct 30, 2015
1 parent 022014f commit 17d56f7
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 6 deletions.
1 change: 1 addition & 0 deletions symmetric-client-clib/inc/model/Router.h
Expand Up @@ -47,5 +47,6 @@ typedef struct SymRouter {
} SymRouter;

SymRouter * SymRouter_new(SymRouter *this);
void SymRouter_destroy(SymRouter *this);

#endif
Expand Up @@ -28,7 +28,6 @@

typedef struct SymFileTransportManager {
SymTransportManager super;
void (*destroy)(struct SymFileTransportManager *this);
} SymFileTransportManager;

SymFileTransportManager * SymFileTransportManager_new(SymFileTransportManager *this, SymParameterService *parameterService);
Expand Down
19 changes: 19 additions & 0 deletions symmetric-client-clib/src/core/SymEngine.c
Expand Up @@ -130,6 +130,25 @@ void SymEngine_destroy(SymEngine *this) {
this->triggerRouterService->destroy(this->triggerRouterService);
this->dialect->destroy(this->dialect);
this->platform->destroy(this->platform);
this->purgeService->destroy(this->purgeService);
this->pushService->destroy(this->pushService);
this->pullService->destroy(this->pullService);
this->offlinePushService->destroy(this->offlinePushService);
this->offlinePullService->destroy(this->offlinePullService);
this->routerService->destroy(this->routerService);
this->registrationService->destroy(this->registrationService);
this->configurationService->destroy(this->configurationService);
this->platform->destroy(this->platform);
this->dataLoaderService->destroy(this->dataLoaderService);
this->transportManager->destroy(this->transportManager);
this->offlineTransportManager->destroy(this->offlineTransportManager);
this->incomingBatchService->destroy(this->incomingBatchService);
this->outgoingBatchService->destroy(this->outgoingBatchService);
this->acknowledgeService->destroy(this->acknowledgeService);
this->dataExtractorService->destroy(this->dataExtractorService);
this->dataService->destroy(this->dataService);
this->nodeService->destroy(this->nodeService);
this->parameterService->destroy(this->parameterService);
free(this);
}

Expand Down
24 changes: 24 additions & 0 deletions symmetric-client-clib/src/model/NodeHost.c
Expand Up @@ -36,6 +36,30 @@ void SymNodeHost_refresh(SymNodeHost *this) {
}

void SymNodeHost_destroy(SymNodeHost *this) {
if (this->hostName) {
free(this->hostName);
}
if (this->ipAddress) {
free(this->ipAddress);
}
if (this->osArch) {
free(this->osArch);
}
if (this->osName) {
free(this->osName);
}
if (this->osVersion) {
free(this->osVersion);
}
if (this->osUser) {
free(this->osUser);
}
if (this->timezoneOffset) {
free(this->timezoneOffset);
}
if (this->heartbeatTime) {
this->heartbeatTime->destroy(this->heartbeatTime);
}

free(this);
}
Expand Down
13 changes: 13 additions & 0 deletions symmetric-client-clib/src/model/Sequence.c
Expand Up @@ -21,6 +21,19 @@
#include "model/Sequence.h"

void SymSequence_destroy(SymSequence *this) {
if (this->sequenceName) {
free(this->sequenceName);
}
if (this->createTime) {
this->createTime->destroy(this->createTime);
}
if (this->lastUpdateBy) {
free(this->lastUpdateBy);
}
if (this->lastUpdateTime) {
this->lastUpdateTime->destroy(this->lastUpdateTime);
}

free(this);
}

Expand Down
5 changes: 4 additions & 1 deletion symmetric-client-clib/src/service/NodeService.c
Expand Up @@ -190,6 +190,7 @@ unsigned short SymNodeService_updateNode(SymNodeService *this, SymNode *node) {
char *syncEnabled = SymStringUtils_format("%d", node->syncEnabled);
char *batchToSendCount = SymStringUtils_format("%d", node->batchToSendCount);
char *batchInErrorCount = SymStringUtils_format("%d", node->batchInErrorCount);
char *timezoneOffset = SymAppUtils_getTimezoneOffset();

SymStringArray *args = SymStringArray_new(NULL);
args->add(args, node->nodeGroupId);
Expand All @@ -201,7 +202,7 @@ unsigned short SymNodeService_updateNode(SymNodeService *this, SymNode *node) {
args->add(args, node->syncUrl);
args->add(args, now->dateTimeString);
args->add(args, syncEnabled);
args->add(args, SymAppUtils_getTimezoneOffset());
args->add(args, timezoneOffset);
args->add(args, batchToSendCount);
args->add(args, batchInErrorCount);
args->add(args, node->createdAtNodeId);
Expand All @@ -212,6 +213,7 @@ unsigned short SymNodeService_updateNode(SymNodeService *this, SymNode *node) {
unsigned short updated = sqlTemplate->update(sqlTemplate,
SYM_SQL_UPDATE_NODE, args, NULL, &error) == 1;

free(timezoneOffset);
free(syncEnabled);
free(batchToSendCount);
free(batchInErrorCount);
Expand Down Expand Up @@ -305,6 +307,7 @@ void SymNodeService_updateNodeHostForCurrentNode(SymNodeService *this) {
nodeHostForCurrentNode->refresh(nodeHostForCurrentNode);
nodeHostForCurrentNode->lastRestartTime = this->lastRestartTime;
SymNodeService_updateNodeHost(this, nodeHostForCurrentNode);
nodeHostForCurrentNode->destroy(nodeHostForCurrentNode);
}

SymList * SymNodeService_findEnabledNodesFromNodeGroup(SymNodeService *this, char *nodeGroupId) {
Expand Down
9 changes: 7 additions & 2 deletions symmetric-client-clib/src/service/RouterService.c
Expand Up @@ -199,20 +199,25 @@ static int SymRouterService_selectDataAndRoute(SymRouterService *this, SymChanne
context->statDataRoutedCount += totalDataCount;
iter->destroy(iter);
dataList->destroy(dataList);
reader->destroy(reader);
return totalDataEventCount;
}

static int SymRouterService_routeDataForChannel(SymRouterService *this, SymChannel *nodeChannel, SymNode *sourceNode) {
SymSqlTemplate *sqlTemplate = this->platform->getSqlTemplate(this->platform);
SymSqlTransaction *sqlTrans = sqlTemplate->startSqlTransaction(sqlTemplate);
SymChannelRouterContext *context = SymChannelRouterContext_new(NULL, sourceNode->nodeId, nodeChannel,
sqlTemplate->startSqlTransaction(sqlTemplate));
sqlTrans);
int dataCount = SymRouterService_selectDataAndRoute(this, context);
if (dataCount > 0) {
long insertTs = time(NULL);
this->dataService->insertDataEvents(this->dataService, context->sqlTransaction, context->dataEventList);
SymRouterService_completeBatchesAndCommit(this, context);
context->statInsertDataEventsMs += ((time(NULL) - insertTs) * 1000);
}

// sqlTrans->destroy(sqlTrans);
context->destroy(context);
return dataCount;
}

Expand Down Expand Up @@ -247,7 +252,7 @@ long SymRouterService_routeData(SymRouterService *this) {
}

void SymRouterService_destroy(SymRouterService *this) {
SymMap_destroy(this->routers);
this->routers->destroyAll(this->routers, (void *) SymRouter_destroy);
free(this);
}

Expand Down
Expand Up @@ -80,6 +80,6 @@ SymFileTransportManager * SymFileTransportManager_new(SymFileTransportManager *t
super->getPullTransport = (void *) &SymFileTransportManager_getPullTransport;
super->getPushTransport = (void *) &SymFileTransportManager_getPushTransport;
super->readAcknowledgement = (void *) SymFileTransportManager_readAcknowledgement;
this->destroy = (void *) &SymFileTransportManager_destroy;
super->destroy = (void *) &SymFileTransportManager_destroy;
return this;
}
2 changes: 1 addition & 1 deletion symmetric-client-clib/src/util/Properties.c
Expand Up @@ -132,7 +132,7 @@ SymProperties * SymProperties_newWithFile(SymProperties *this, char *argPath) {
return NULL;
}

SymStringBuilder *buff = SymStringBuilder_new(NULL);
SymStringBuilder *buff = SymStringBuilder_newWithSize(4096);

while (fgets(inputBuffer, BUFFER_SIZE, file) != NULL) {
buff->append(buff, inputBuffer);
Expand Down

0 comments on commit 17d56f7

Please sign in to comment.