From 9cc37f61db76037215baa9b359b429d052130331 Mon Sep 17 00:00:00 2001 From: Netaji Panigrahi <114923459+NetajiPanigrahi@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:08:48 +0530 Subject: [PATCH] Update rtrouteBase.c --- src/rtmessage/rtrouteBase.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rtmessage/rtrouteBase.c b/src/rtmessage/rtrouteBase.c index f9d1c700..d8a97a3d 100644 --- a/src/rtmessage/rtrouteBase.c +++ b/src/rtmessage/rtrouteBase.c @@ -61,12 +61,17 @@ 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); @@ -130,7 +135,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; } @@ -577,6 +582,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;