projects
/
yaz-moved-to-github.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
86c4a75
)
tcpip comstack: fix leak for getaddrinfo
author
Adam Dickmeiss
<adam@indexdata.dk>
Mon, 23 Nov 2009 14:31:51 +0000
(15:31 +0100)
committer
Adam Dickmeiss
<adam@indexdata.dk>
Mon, 23 Nov 2009 14:31:51 +0000
(15:31 +0100)
src/tcpip.c
patch
|
blob
|
history
diff --git
a/src/tcpip.c
b/src/tcpip.c
index
416b707
..
3fa26de
100644
(file)
--- a/
src/tcpip.c
+++ b/
src/tcpip.c
@@
-423,6
+423,7
@@
void *tcpip_straddr(COMSTACK h, const char *str)
{
tcpip_state *sp = (tcpip_state *)h->cprivate;
const char *port = "210";
{
tcpip_state *sp = (tcpip_state *)h->cprivate;
const char *port = "210";
+ struct addrinfo *ai;
if (h->protocol == PROTO_HTTP)
port = "80";
if (!tcpip_init())
if (h->protocol == PROTO_HTTP)
port = "80";
if (!tcpip_init())
@@
-434,7
+435,6
@@
void *tcpip_straddr(COMSTACK h, const char *str)
if (sp->ai && h->state == CS_ST_UNBND)
{
int s = -1;
if (sp->ai && h->state == CS_ST_UNBND)
{
int s = -1;
- struct addrinfo *ai;
/* try to make IPV6 socket first */
for (ai = sp->ai; ai; ai = ai->ai_next)
{
/* try to make IPV6 socket first */
for (ai = sp->ai; ai; ai = ai->ai_next)
{
@@
-442,10
+442,7
@@
void *tcpip_straddr(COMSTACK h, const char *str)
{
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (s != -1)
{
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (s != -1)
- {
- sp->ai = ai;
break;
break;
- }
}
}
if (s == -1)
}
}
if (s == -1)
@@
-455,20
+452,18
@@
void *tcpip_straddr(COMSTACK h, const char *str)
{
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (s != -1)
{
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (s != -1)
- {
- sp->ai = ai;
break;
break;
- }
}
}
if (s == -1)
return 0;
}
}
if (s == -1)
return 0;
+ assert(ai);
h->iofile = s;
if (!tcpip_set_blocking(h, h->flags))
return 0;
}
h->iofile = s;
if (!tcpip_set_blocking(h, h->flags))
return 0;
}
- return sp->ai;
+ return ai;
}
#else
void *tcpip_straddr(COMSTACK h, const char *str)
}
#else
void *tcpip_straddr(COMSTACK h, const char *str)
@@
-512,6
+507,7
@@
int tcpip_more(COMSTACK h)
int tcpip_connect(COMSTACK h, void *address)
{
#if HAVE_GETADDRINFO
int tcpip_connect(COMSTACK h, void *address)
{
#if HAVE_GETADDRINFO
+ struct addrinfo *ai = (struct addrinfo *) address;
tcpip_state *sp = (tcpip_state *)h->cprivate;
#else
struct sockaddr_in *add = (struct sockaddr_in *) address;
tcpip_state *sp = (tcpip_state *)h->cprivate;
#else
struct sockaddr_in *add = (struct sockaddr_in *) address;
@@
-528,13
+524,6
@@
int tcpip_connect(COMSTACK h, void *address)
h->cerrno = CSOUTSTATE;
return -1;
}
h->cerrno = CSOUTSTATE;
return -1;
}
-#if HAVE_GETADDRINFO
- if (sp->ai != (struct addrinfo *) address)
- {
- h->cerrno = CSOUTSTATE;
- return -1;
- }
-#endif
#ifdef __sun__
/* On Suns, you must set a bigger Receive Buffer BEFORE a call to connect
* This gives the connect a chance to negotiate with the other side
#ifdef __sun__
/* On Suns, you must set a bigger Receive Buffer BEFORE a call to connect
* This gives the connect a chance to negotiate with the other side
@@
-563,7
+552,7
@@
int tcpip_connect(COMSTACK h, void *address)
#endif
#if HAVE_GETADDRINFO
#endif
#if HAVE_GETADDRINFO
- r = connect(h->iofile, sp->ai->ai_addr, sp->ai->ai_addrlen);
+ r = connect(h->iofile, ai->ai_addr, ai->ai_addrlen);
freeaddrinfo(sp->ai);
sp->ai = 0;
#else
freeaddrinfo(sp->ai);
sp->ai = 0;
#else
@@
-703,7
+692,8
@@
static int tcpip_bind(COMSTACK h, void *address, int mode)
{
int r;
tcpip_state *sp = (tcpip_state *)h->cprivate;
{
int r;
tcpip_state *sp = (tcpip_state *)h->cprivate;
-#if HAVE_GETADDRINFO
+#if HAVE_GETADDRINFO
+ struct addrinfo *ai = (struct addrinfo *) address;
#else
struct sockaddr *addr = (struct sockaddr *)address;
#endif
#else
struct sockaddr *addr = (struct sockaddr *)address;
#endif
@@
-713,14
+703,6
@@
static int tcpip_bind(COMSTACK h, void *address, int mode)
int one = 1;
#endif
int one = 1;
#endif
-#if HAVE_GETADDRINFO
- if (sp->ai != (struct addrinfo *) address)
- {
- h->cerrno = CSOUTSTATE;
- return -1;
- }
-#endif
-
#if HAVE_GNUTLS_H
if (h->type == ssl_type && !sp->session)
{
#if HAVE_GNUTLS_H
if (h->type == ssl_type && !sp->session)
{
@@
-797,7
+779,7
@@
static int tcpip_bind(COMSTACK h, void *address, int mode)
#endif
tcpip_setsockopt(h->iofile);
#if HAVE_GETADDRINFO
#endif
tcpip_setsockopt(h->iofile);
#if HAVE_GETADDRINFO
- r = bind(h->iofile, sp->ai->ai_addr, sp->ai->ai_addrlen);
+ r = bind(h->iofile, ai->ai_addr, ai->ai_addrlen);
freeaddrinfo(sp->ai);
sp->ai = 0;
#else
freeaddrinfo(sp->ai);
sp->ai = 0;
#else