Mercurial > pidgin.yaz
changeset 32252:9ceccb623544
Rationalize nat_pmp.c:default_gw() and free leaked buffer.
Thanks to Thijs Alkemade for finding this problem.
Fixes #14424
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Mon, 15 Aug 2011 04:16:23 +0000 |
parents | 58799e44a5ef |
children | c4859b6b1d74 |
files | libpurple/nat-pmp.c |
diffstat | 1 files changed, 6 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/nat-pmp.c Sun Aug 14 20:19:43 2011 +0000 +++ b/libpurple/nat-pmp.c Mon Aug 15 04:16:23 2011 +0000 @@ -182,7 +182,6 @@ struct rt_msghdr *rtm; struct sockaddr *sa; struct sockaddr_in *sin = NULL; - gboolean found = FALSE; mib[0] = CTL_NET; mib[1] = PF_ROUTE; /* entire routing table or a subset of it */ @@ -207,6 +206,7 @@ /* Read the routing table into buf */ if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { + free(buf); purple_debug_warning("nat-pmp", "sysctl: net.route.0.0.dump\n"); return NULL; } @@ -220,9 +220,10 @@ if (sa->sa_family == AF_INET) { - sin = (struct sockaddr_in*) sa; + struct sockaddr_in *cursin = (struct sockaddr_in*) sa; - if ((rtm->rtm_flags & RTF_GATEWAY) && sin->sin_addr.s_addr == INADDR_ANY) + if ((rtm->rtm_flags & RTF_GATEWAY) + && cursin->sin_addr.s_addr == INADDR_ANY) { /* We found the default route. Now get the destination address and netmask. */ struct sockaddr *rti_info[RTAX_MAX]; @@ -251,7 +252,6 @@ memcpy(sin, rti_info[RTAX_GATEWAY], sizeof(struct sockaddr_in)); purple_debug_info("nat-pmp", "Found a default gateway\n"); - found = TRUE; break; } } @@ -259,7 +259,8 @@ } } - return (found ? sin : NULL); + free(buf); + return sin; } /*!