# HG changeset patch # User Thomas Butter # Date 1123537424 0 # Node ID ff728e84d59a75f7d58e05163a1af474ec985e2d # Parent 46086fcc82b79f7863647c2b3ffc66ca92f98e5b [gaim-migrate @ 13344] Changes by Adam Warrington Fixes a crash on UPnP timeout committer: Tailor Script diff -r 46086fcc82b7 -r ff728e84d59a src/network.c --- a/src/network.c Mon Aug 08 19:56:41 2005 +0000 +++ b/src/network.c Mon Aug 08 21:43:44 2005 +0000 @@ -134,8 +134,8 @@ const char * gaim_network_get_my_ip(int fd) { - const char *ip = NULL; - const char *controlURL = NULL; + char *ip = NULL; + char *controlURL = NULL; /* Check if the user specified an IP manually */ if (!gaim_prefs_get_bool("/core/network/auto_ip")) { @@ -147,6 +147,7 @@ /* attempt to get the ip from a NAT device */ if ((controlURL = gaim_upnp_discover()) != NULL) { ip = gaim_upnp_get_public_ip(controlURL); + free(controlURL); if (ip != NULL) return ip; } @@ -160,7 +161,7 @@ { int listenfd = -1; const int on = 1; - const char *controlURL = NULL; + char *controlURL = NULL; #if HAVE_GETADDRINFO int errnum; struct addrinfo hints, *res, *next; @@ -236,6 +237,7 @@ gaim_upnp_remove_port_mapping(controlURL, port, "TCP"); gaim_upnp_set_port_mapping(controlURL, port, "TCP"); } + free(controlURL); } gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd)); diff -r 46086fcc82b7 -r ff728e84d59a src/upnp.c --- a/src/upnp.c Mon Aug 08 19:56:41 2005 +0000 +++ b/src/upnp.c Mon Aug 08 21:43:44 2005 +0000 @@ -151,7 +151,7 @@ static void gaim_upnp_timeout(gpointer data, - gint source, + gint source, GaimInputCondition cond) { HRD* hrd = data; @@ -244,7 +244,7 @@ hrd->done = FALSE; hrd->recvBuffer = (char*)malloc(MAX_DESCRIPTION_RECIEVE_SIZE); - if(hrd == NULL) { + if(hrd->recvBuffer == NULL) { gaim_debug_info("upnp", "gaim_upnp_http_request(): Failed in recvBuffer MALLOC\n\n"); free(hrd); @@ -644,7 +644,6 @@ gaim_timeout_remove(hrd->tima); length = sizeof(struct sockaddr_in); - hrd->recvBuffer = (char*)malloc(MAX_DISCOVERY_RECIEVE_SIZE); do { sizeRecv = recvfrom(sock, hrd->recvBuffer, @@ -665,6 +664,7 @@ } + char* gaim_upnp_discover(void) { @@ -678,14 +678,19 @@ char *controlURL = NULL; HRD* hrd = (HRD*)malloc(sizeof(HRD)); - hrd->recvBuffer = NULL; - hrd->done = FALSE; + if(hrd == NULL) { + gaim_debug_info("upnp", + "gaim_upnp_discover(): Failed in hrd MALLOC\n\n"); + return NULL; + } sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock == -1) { close(sock); gaim_debug_info("upnp", "gaim_upnp_discover(): Failed In sock creation\n\n"); + free(hrd->recvBuffer); + free(hrd); return NULL; } @@ -695,6 +700,8 @@ close(sock); gaim_debug_info("upnp", "gaim_upnp_discover(): Failed In gethostbyname\n\n"); + free(hrd->recvBuffer); + free(hrd); return NULL; } @@ -710,6 +717,18 @@ recvSuccess = TRUE; totalSizeSent = 0; + hrd->recvBuffer = NULL; + hrd->totalSizeRecv = 0; + hrd->done = FALSE; + + hrd->recvBuffer = (char*)malloc(MAX_DISCOVERY_RECIEVE_SIZE); + if(hrd->recvBuffer == NULL) { + gaim_debug_info("upnp", + "gaim_upnp_discover(): Failed in hrd->recvBuffer MALLOC\n\n"); + free(hrd); + return NULL; + } + while(totalSizeSent < strlen(sendMessage)) { sizeSent = sendto(sock,(void*)&sendMessage[totalSizeSent], strlen(&sendMessage[totalSizeSent]),0, @@ -742,6 +761,8 @@ strlen(hrd->recvBuffer)))==NULL) { gaim_debug_info("upnp", "gaim_upnp_discover(): Failed In parse response\n\n"); + free(hrd->recvBuffer); + free(hrd); return NULL; } } @@ -752,6 +773,12 @@ i = NUM_UDP_ATTEMPTS; } } + + if(hrd->recvBuffer != NULL) { + free(hrd->recvBuffer); + } + free(hrd); + if(!sentSuccess || !recvSuccess) { close(sock); gaim_debug_info("upnp", diff -r 46086fcc82b7 -r ff728e84d59a src/upnp.h --- a/src/upnp.h Mon Aug 08 19:56:41 2005 +0000 +++ b/src/upnp.h Mon Aug 08 21:43:44 2005 +0000 @@ -47,6 +47,7 @@ char* gaim_upnp_discover(void); + /** * Gets the IP address from a UPnP enabled IGD that sits on the local * network, so when getting the network IP, instead of returning the @@ -67,7 +68,6 @@ * @param controlURL The control URL retrieved from gaim_upnp_discover. * @param portMap The port to map to this client * @param protocol The protocol to map, either "TCP" or "UDP" - * @param internalIP The internal IP to map to * * @return TRUE if success, FALSE if something went wrong. */