diff options
| author | Paul Aurich <paul@darkrain42.org> | 2012-05-21 19:44:08 -0700 |
|---|---|---|
| committer | Paul Aurich <paul@darkrain42.org> | 2012-05-21 19:44:08 -0700 |
| commit | d777341eafe019dcd6da0547b82cf24abfb34594 (patch) | |
| tree | 35e4b3a6b09f85687483ae7b967a7a94fab5b943 | |
| parent | 05535a19f81d181b7e15d241892e794a00905bb9 (diff) | |
| download | luasocket-d777341eafe019dcd6da0547b82cf24abfb34594.tar.gz luasocket-d777341eafe019dcd6da0547b82cf24abfb34594.tar.bz2 luasocket-d777341eafe019dcd6da0547b82cf24abfb34594.zip | |
tcp: Initialize clnt->family in :accept()
Also unconditionally zero out the structs when allocated, for
good measure.
| -rw-r--r-- | src/tcp.c | 6 |
1 files changed, 5 insertions, 1 deletions
| @@ -192,12 +192,14 @@ static int meth_accept(lua_State *L) | |||
| 192 | p_tcp clnt = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); | 192 | p_tcp clnt = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); |
| 193 | auxiliar_setclass(L, "tcp{client}", -1); | 193 | auxiliar_setclass(L, "tcp{client}", -1); |
| 194 | /* initialize structure fields */ | 194 | /* initialize structure fields */ |
| 195 | memset(clnt, 0, sizeof(t_tcp)); | ||
| 195 | socket_setnonblocking(&sock); | 196 | socket_setnonblocking(&sock); |
| 196 | clnt->sock = sock; | 197 | clnt->sock = sock; |
| 197 | io_init(&clnt->io, (p_send) socket_send, (p_recv) socket_recv, | 198 | io_init(&clnt->io, (p_send) socket_send, (p_recv) socket_recv, |
| 198 | (p_error) socket_ioerror, &clnt->sock); | 199 | (p_error) socket_ioerror, &clnt->sock); |
| 199 | timeout_init(&clnt->tm, -1, -1); | 200 | timeout_init(&clnt->tm, -1, -1); |
| 200 | buffer_init(&clnt->buf, &clnt->io, &clnt->tm); | 201 | buffer_init(&clnt->buf, &clnt->io, &clnt->tm); |
| 202 | clnt->family = server->family; | ||
| 201 | return 1; | 203 | return 1; |
| 202 | } else { | 204 | } else { |
| 203 | lua_pushnil(L); | 205 | lua_pushnil(L); |
| @@ -354,6 +356,7 @@ static int tcp_create(lua_State *L, int family) { | |||
| 354 | if (!err) { | 356 | if (!err) { |
| 355 | /* allocate tcp object */ | 357 | /* allocate tcp object */ |
| 356 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); | 358 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); |
| 359 | memset(tcp, 0, sizeof(t_tcp)); | ||
| 357 | /* set its type as master object */ | 360 | /* set its type as master object */ |
| 358 | auxiliar_setclass(L, "tcp{master}", -1); | 361 | auxiliar_setclass(L, "tcp{master}", -1); |
| 359 | /* initialize remaining structure fields */ | 362 | /* initialize remaining structure fields */ |
| @@ -368,7 +371,7 @@ static int tcp_create(lua_State *L, int family) { | |||
| 368 | (p_error) socket_ioerror, &tcp->sock); | 371 | (p_error) socket_ioerror, &tcp->sock); |
| 369 | timeout_init(&tcp->tm, -1, -1); | 372 | timeout_init(&tcp->tm, -1, -1); |
| 370 | buffer_init(&tcp->buf, &tcp->io, &tcp->tm); | 373 | buffer_init(&tcp->buf, &tcp->io, &tcp->tm); |
| 371 | tcp->family = family; | 374 | tcp->family = family; |
| 372 | return 1; | 375 | return 1; |
| 373 | } else { | 376 | } else { |
| 374 | lua_pushnil(L); | 377 | lua_pushnil(L); |
| @@ -435,6 +438,7 @@ static int global_connect(lua_State *L) { | |||
| 435 | struct addrinfo bindhints, connecthints; | 438 | struct addrinfo bindhints, connecthints; |
| 436 | const char *err = NULL; | 439 | const char *err = NULL; |
| 437 | /* initialize tcp structure */ | 440 | /* initialize tcp structure */ |
| 441 | memset(tcp, 0, sizeof(t_tcp)); | ||
| 438 | io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv, | 442 | io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv, |
| 439 | (p_error) socket_ioerror, &tcp->sock); | 443 | (p_error) socket_ioerror, &tcp->sock); |
| 440 | timeout_init(&tcp->tm, -1, -1); | 444 | timeout_init(&tcp->tm, -1, -1); |
