moonbridge
changeset 117:d8469c1039e6
Bugfixes regarding treatment of memory allocation errors and closing file descriptors
author | jbe |
---|---|
date | Fri Apr 10 02:40:43 2015 +0200 (2015-04-10) |
parents | 2ab19e15aa6b |
children | 118e320a7812 |
files | moonbridge_io.c |
line diff
1.1 --- a/moonbridge_io.c Fri Apr 10 02:24:54 2015 +0200 1.2 +++ b/moonbridge_io.c Fri Apr 10 02:40:43 2015 +0200 1.3 @@ -769,6 +769,7 @@ 1.4 if (strlen(path) > path_maxlen) luaL_error(L, "Path too long; only %i characters allowed", path_maxlen); 1.5 strcpy(sockaddr.sun_path, path); 1.6 listener = lua_newuserdata(L, sizeof(moonbr_io_listener_t)); 1.7 + listener->fd = -1; 1.8 luaL_setmetatable(L, MOONBR_IO_LISTENER_MT_REGKEY); 1.9 sock = socket( 1.10 PF_LOCAL, 1.11 @@ -810,6 +811,7 @@ 1.12 host = luaL_optstring(L, 1, NULL); 1.13 port = luaL_checkstring(L, 2); 1.14 listener = lua_newuserdata(L, sizeof(moonbr_io_listener_t)); 1.15 + listener->fd = -1; 1.16 luaL_setmetatable(L, MOONBR_IO_LISTENER_MT_REGKEY); 1.17 hints.ai_family = AF_UNSPEC; 1.18 hints.ai_socktype = SOCK_STREAM; 1.19 @@ -940,7 +942,7 @@ 1.20 static int moonbr_io_listenergc(lua_State *L) { 1.21 moonbr_io_listener_t *listener; 1.22 listener = luaL_checkudata(L, 1, MOONBR_IO_LISTENER_MT_REGKEY); 1.23 - if (listener->fd) close(listener->fd); 1.24 + if (listener->fd >= 0) close(listener->fd); 1.25 listener->fd = -1; 1.26 return 0; 1.27 }