[package] quagga: add upstream patches fixing memory leaks
[openwrt/svn-archive/archive.git] / net / quagga / patches / 180-fix-lib-connect-memleak.patch
1 From b24b19f719fdd9c3d61a0c93552cd64d832d964c Mon Sep 17 00:00:00 2001
2 From: Stephen Hemminger <shemminger@vyatta.com>
3 Date: Tue, 6 Dec 2011 14:09:18 +0400
4 Subject: [PATCH] lib: fix memory leak on connect() failure
5
6 Change sockunion_log() to not use strdup(). This fixes a small memory
7 leak that occurs on every failed connect(), and is simpler/cleaner.
8 ---
9 lib/sockunion.c | 23 +++++++++++------------
10 1 files changed, 11 insertions(+), 12 deletions(-)
11
12 --- a/lib/sockunion.c
13 +++ b/lib/sockunion.c
14 @@ -297,27 +297,24 @@ sockunion_sizeof (union sockunion *su)
15 }
16
17 /* return sockunion structure : this function should be revised. */
18 -static char *
19 -sockunion_log (union sockunion *su)
20 +static const char *
21 +sockunion_log (union sockunion *su, char *buf, size_t len)
22 {
23 - static char buf[SU_ADDRSTRLEN];
24 -
25 switch (su->sa.sa_family)
26 {
27 case AF_INET:
28 - snprintf (buf, SU_ADDRSTRLEN, "%s", inet_ntoa (su->sin.sin_addr));
29 - break;
30 + return inet_ntop(AF_INET, &su->sin.sin_addr, buf, len);
31 +
32 #ifdef HAVE_IPV6
33 case AF_INET6:
34 - snprintf (buf, SU_ADDRSTRLEN, "%s",
35 - inet_ntop (AF_INET6, &(su->sin6.sin6_addr), buf, SU_ADDRSTRLEN));
36 + return inet_ntop(AF_INET6, &(su->sin6.sin6_addr), buf, len);
37 break;
38 #endif /* HAVE_IPV6 */
39 +
40 default:
41 - snprintf (buf, SU_ADDRSTRLEN, "af_unknown %d ", su->sa.sa_family);
42 - break;
43 + snprintf (buf, len, "af_unknown %d ", su->sa.sa_family);
44 + return buf;
45 }
46 - return (XSTRDUP (MTYPE_TMP, buf));
47 }
48
49 /* sockunion_connect returns
50 @@ -379,8 +376,10 @@ sockunion_connect (int fd, union sockuni
51 {
52 if (errno != EINPROGRESS)
53 {
54 + char str[SU_ADDRSTRLEN];
55 zlog_info ("can't connect to %s fd %d : %s",
56 - sockunion_log (&su), fd, safe_strerror (errno));
57 + sockunion_log (&su, str, sizeof str),
58 + fd, safe_strerror (errno));
59 return connect_error;
60 }
61 }