d0b63ae892
Signed-off-by: Oliver Smith <olipro@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa> git-svn-id: svn://svn.openwrt.org/openwrt/packages@31190 3c298f89-4303-0410-b956-a3cf2f4a3e73
62 lines
1.9 KiB
Diff
62 lines
1.9 KiB
Diff
From b24b19f719fdd9c3d61a0c93552cd64d832d964c Mon Sep 17 00:00:00 2001
|
|
From: Stephen Hemminger <shemminger@vyatta.com>
|
|
Date: Tue, 6 Dec 2011 14:09:18 +0400
|
|
Subject: [PATCH] lib: fix memory leak on connect() failure
|
|
|
|
Change sockunion_log() to not use strdup(). This fixes a small memory
|
|
leak that occurs on every failed connect(), and is simpler/cleaner.
|
|
---
|
|
lib/sockunion.c | 23 +++++++++++------------
|
|
1 files changed, 11 insertions(+), 12 deletions(-)
|
|
|
|
--- a/lib/sockunion.c
|
|
+++ b/lib/sockunion.c
|
|
@@ -297,27 +297,24 @@ sockunion_sizeof (union sockunion *su)
|
|
}
|
|
|
|
/* return sockunion structure : this function should be revised. */
|
|
-static char *
|
|
-sockunion_log (union sockunion *su)
|
|
+static const char *
|
|
+sockunion_log (union sockunion *su, char *buf, size_t len)
|
|
{
|
|
- static char buf[SU_ADDRSTRLEN];
|
|
-
|
|
switch (su->sa.sa_family)
|
|
{
|
|
case AF_INET:
|
|
- snprintf (buf, SU_ADDRSTRLEN, "%s", inet_ntoa (su->sin.sin_addr));
|
|
- break;
|
|
+ return inet_ntop(AF_INET, &su->sin.sin_addr, buf, len);
|
|
+
|
|
#ifdef HAVE_IPV6
|
|
case AF_INET6:
|
|
- snprintf (buf, SU_ADDRSTRLEN, "%s",
|
|
- inet_ntop (AF_INET6, &(su->sin6.sin6_addr), buf, SU_ADDRSTRLEN));
|
|
+ return inet_ntop(AF_INET6, &(su->sin6.sin6_addr), buf, len);
|
|
break;
|
|
#endif /* HAVE_IPV6 */
|
|
+
|
|
default:
|
|
- snprintf (buf, SU_ADDRSTRLEN, "af_unknown %d ", su->sa.sa_family);
|
|
- break;
|
|
+ snprintf (buf, len, "af_unknown %d ", su->sa.sa_family);
|
|
+ return buf;
|
|
}
|
|
- return (XSTRDUP (MTYPE_TMP, buf));
|
|
}
|
|
|
|
/* sockunion_connect returns
|
|
@@ -379,8 +376,10 @@ sockunion_connect (int fd, union sockuni
|
|
{
|
|
if (errno != EINPROGRESS)
|
|
{
|
|
+ char str[SU_ADDRSTRLEN];
|
|
zlog_info ("can't connect to %s fd %d : %s",
|
|
- sockunion_log (&su), fd, safe_strerror (errno));
|
|
+ sockunion_log (&su, str, sizeof str),
|
|
+ fd, safe_strerror (errno));
|
|
return connect_error;
|
|
}
|
|
}
|