mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-11-16 18:28:21 +01:00
tcp: Initialize clnt->family in :accept()
Also unconditionally zero out the structs when allocated, for good measure.
This commit is contained in:
parent
05535a19f8
commit
d777341eaf
@ -192,12 +192,14 @@ static int meth_accept(lua_State *L)
|
|||||||
p_tcp clnt = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));
|
p_tcp clnt = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));
|
||||||
auxiliar_setclass(L, "tcp{client}", -1);
|
auxiliar_setclass(L, "tcp{client}", -1);
|
||||||
/* initialize structure fields */
|
/* initialize structure fields */
|
||||||
|
memset(clnt, 0, sizeof(t_tcp));
|
||||||
socket_setnonblocking(&sock);
|
socket_setnonblocking(&sock);
|
||||||
clnt->sock = sock;
|
clnt->sock = sock;
|
||||||
io_init(&clnt->io, (p_send) socket_send, (p_recv) socket_recv,
|
io_init(&clnt->io, (p_send) socket_send, (p_recv) socket_recv,
|
||||||
(p_error) socket_ioerror, &clnt->sock);
|
(p_error) socket_ioerror, &clnt->sock);
|
||||||
timeout_init(&clnt->tm, -1, -1);
|
timeout_init(&clnt->tm, -1, -1);
|
||||||
buffer_init(&clnt->buf, &clnt->io, &clnt->tm);
|
buffer_init(&clnt->buf, &clnt->io, &clnt->tm);
|
||||||
|
clnt->family = server->family;
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
@ -354,6 +356,7 @@ static int tcp_create(lua_State *L, int family) {
|
|||||||
if (!err) {
|
if (!err) {
|
||||||
/* allocate tcp object */
|
/* allocate tcp object */
|
||||||
p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));
|
p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));
|
||||||
|
memset(tcp, 0, sizeof(t_tcp));
|
||||||
/* set its type as master object */
|
/* set its type as master object */
|
||||||
auxiliar_setclass(L, "tcp{master}", -1);
|
auxiliar_setclass(L, "tcp{master}", -1);
|
||||||
/* initialize remaining structure fields */
|
/* initialize remaining structure fields */
|
||||||
@ -435,6 +438,7 @@ static int global_connect(lua_State *L) {
|
|||||||
struct addrinfo bindhints, connecthints;
|
struct addrinfo bindhints, connecthints;
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
/* initialize tcp structure */
|
/* initialize tcp structure */
|
||||||
|
memset(tcp, 0, sizeof(t_tcp));
|
||||||
io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv,
|
io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv,
|
||||||
(p_error) socket_ioerror, &tcp->sock);
|
(p_error) socket_ioerror, &tcp->sock);
|
||||||
timeout_init(&tcp->tm, -1, -1);
|
timeout_init(&tcp->tm, -1, -1);
|
||||||
|
Loading…
Reference in New Issue
Block a user