projects
/
project
/
luci.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
nixio: Fix accidental closing of file descriptors after dup with two
[project/luci.git]
/
libs
/
nixio
/
src
/
file.c
diff --git
a/libs/nixio/src/file.c
b/libs/nixio/src/file.c
index 482752522737682cbad8e83203b605fd83446ff8..70c717e4e17e62ca8bcce6899ecf0d012d724a09 100644
(file)
--- a/
libs/nixio/src/file.c
+++ b/
libs/nixio/src/file.c
@@
-123,14
+123,18
@@
static int nixio_dup(lua_State *L) {
if (stat == -1) {
return nixio__perror(L);
} else {
if (stat == -1) {
return nixio__perror(L);
} else {
- int *udata = lua_newuserdata(L, sizeof(int));
- if (!udata) {
- return luaL_error(L, "out of memory");
- }
+ if (newfd == -1) {
+ int *udata = lua_newuserdata(L, sizeof(int));
+ if (!udata) {
+ return luaL_error(L, "out of memory");
+ }
- *udata = stat;
- luaL_getmetatable(L, NIXIO_FILE_META);
- lua_setmetatable(L, -2);
+ *udata = stat;
+ luaL_getmetatable(L, NIXIO_FILE_META);
+ lua_setmetatable(L, -2);
+ } else {
+ lua_pushvalue(L, 2);
+ }
return 1;
}
}
return 1;
}
}