Changeset 5058

Show
Ignore:
Timestamp:
07/11/09 09:01:32 (4 years ago)
Author:
Cyrus
Message:

nixio: Fix accidental closing of file descriptors after dup with two
parameters resulting in strange behaviour when spawning processes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/nixio/src/file.c

    r4437 r5058  
    124124        return nixio__perror(L); 
    125125    } else { 
    126         int *udata = lua_newuserdata(L, sizeof(int)); 
    127         if (!udata) { 
    128             return luaL_error(L, "out of memory"); 
    129         } 
    130  
    131         *udata = stat; 
    132         luaL_getmetatable(L, NIXIO_FILE_META); 
    133         lua_setmetatable(L, -2); 
     126        if (newfd == -1) { 
     127            int *udata = lua_newuserdata(L, sizeof(int)); 
     128            if (!udata) { 
     129                return luaL_error(L, "out of memory"); 
     130            } 
     131 
     132            *udata = stat; 
     133            luaL_getmetatable(L, NIXIO_FILE_META); 
     134            lua_setmetatable(L, -2); 
     135        } else { 
     136            lua_pushvalue(L, 2); 
     137        } 
    134138        return 1; 
    135139    }