Skip to content

Commit

Permalink
Rbus fix memory leak (#237)
Browse files Browse the repository at this point in the history
* : Handled error conditions and fixed memory leaks.
  • Loading branch information
NetajiPanigrahi authored Nov 20, 2024
1 parent 64b895e commit 2c3e5e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/rbus/rbus_subscriptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ static void rbusSubscriptions_loadCache(rbusSubscriptions_t subscriptions)
rbusBuffer_Destroy(buff);

if(sub)
free(sub);
subscriptionFree(sub);

if(remove(filePath) != 0)
RBUSLOG_ERROR("failed to remove %s", filePath);
Expand Down Expand Up @@ -665,7 +665,11 @@ static void rbusSubscriptions_saveCache(rbusSubscriptions_t subscriptions)
{
rtListItem_GetData(item, (void**)&sub);
if(!sub)
{
rbusBuffer_Destroy(buff);
fclose(file);
return;
}
rbusBuffer_WriteStringTLV(buff, sub->listener, strlen(sub->listener)+1);
rbusBuffer_WriteStringTLV(buff, sub->eventName, strlen(sub->eventName)+1);
rbusBuffer_WriteInt32TLV(buff, sub->componentId);
Expand Down
12 changes: 10 additions & 2 deletions src/rtmessage/rtrouteBase.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ rtRouteBase_BindListener(char const* socket_name, int no_delay, int indefinite_r
unsigned int num_retries = 1;

listener = (rtListener *)rt_malloc(sizeof(rtListener));
if (!listener)
return rtErrorFromErrno(ENOMEM);

listener->fd = -1;
memset(&listener->local_endpoint, 0, sizeof(struct sockaddr_storage));

err = rtSocketStorage_FromString(&listener->local_endpoint, socket_name);
if (err != RT_OK)
return err;
{
free(listener);
return err;
}

rtLog_Debug("binding listener:%s", socket_name);

Expand Down Expand Up @@ -130,7 +136,7 @@ rtRouteBase_BindListener(char const* socket_name, int no_delay, int indefinite_r
{
rtLog_Warn("failed to set socket to listen mode. %s", rtStrError(errno));
rtRouteBase_CloseListener(listener);
free(listener);
free(listener);
return RT_FAIL;
}

Expand Down Expand Up @@ -577,6 +583,8 @@ rtRouteDirect_StartInstance(const char* socket_name, rtDriectClientHandler messa
}

route = (rtRouteEntry *)rt_malloc(sizeof(rtRouteEntry));
if (!route)
return rtErrorFromErrno(ENOMEM);
route->subscription = NULL;
strncpy(route->expression, "_RTDIRECT>", RTMSG_MAX_EXPRESSION_LEN-1);
route->message_handler = _rtdirect_OnMessage;
Expand Down

0 comments on commit 2c3e5e8

Please sign in to comment.