Skip to content

Commit

Permalink
Merge pull request #425 from shilpa24balaji/memFreeMetadata
Browse files Browse the repository at this point in the history
Free memory in Parodus during exit/shutdown
  • Loading branch information
schmidtw committed Jul 20, 2023
2 parents 118e8ee + 03a5b96 commit 85a0d9b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
47 changes: 47 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,53 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
return 0;
}

void free_cfg(ParodusCfg *cfg)
{
if(cfg != NULL)
{
if (cfg->mtls_client_cert_path != NULL )
{
free(cfg->mtls_client_cert_path);
cfg->mtls_client_cert_path = NULL;
}
if(cfg->connection_health_file != NULL)
{
free(cfg->connection_health_file);
cfg->connection_health_file = NULL;
}
if(cfg->token_server_url != NULL)
{
free(cfg->token_server_url );
cfg->token_server_url = NULL;
}
if(cfg->mtls_client_key_path != NULL)
{
free(cfg->mtls_client_key_path);
cfg->mtls_client_key_path = NULL;
}
if(cfg->client_cert_path != NULL)
{
free(cfg->client_cert_path);
cfg->client_cert_path = NULL;
}
if(cfg->crud_config_file != NULL)
{
free(cfg->crud_config_file);
cfg->crud_config_file = NULL;
}
if(cfg->close_reason_file != NULL)
{
free(cfg->close_reason_file);
cfg->close_reason_file = NULL;
}
if(cfg->cloud_disconnect != NULL)
{
free(cfg->cloud_disconnect);
cfg->cloud_disconnect = NULL;
}
}
}

void setDefaultValuesToCfg(ParodusCfg *cfg)
{
if(cfg == NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg);
* or -1 if error
*/
int parseCommandLine(int argc,char **argv,ParodusCfg * cfg);

void free_cfg(ParodusCfg *cfg);
void setDefaultValuesToCfg(ParodusCfg *cfg);
// Accessor for the global config structure.
ParodusCfg *get_parodus_cfg(void);
Expand Down
3 changes: 3 additions & 0 deletions src/conn_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ void createSocketConnection(void (* initKeypress)())
nopoll_ctx_unref(ctx);
nopoll_cleanup_library();
curl_global_cleanup();
clear_metadata();
rdk_logger_deinit();
free_server_list(&server_list);
}

void shutdownSocketConnection(char *reason) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int main( int argc, char **argv)
curl_global_init(CURL_GLOBAL_DEFAULT);

createSocketConnection( NULL);

free_cfg(cfg);
return 0;
}

Expand Down
5 changes: 5 additions & 0 deletions src/upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ void packMetaData()
ParodusError("Failed to encode metadata\n");
}
}

void clear_metadata(){
if(metadataPack != NULL)
free(metadataPack);
}

/*
* @brief To handle UpStream messages which is received from nanomsg server socket
Expand Down
1 change: 1 addition & 0 deletions src/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int subscribeCurrentActiveInterfaceEvent();
UpStreamMsg * get_global_UpStreamMsgQ(void);
pthread_cond_t *get_global_nano_con(void);
pthread_mutex_t *get_global_nano_mut(void);
void clear_metadata();

#ifdef __cplusplus
}
Expand Down

0 comments on commit 85a0d9b

Please sign in to comment.