4 Commits

Author SHA1 Message Date
Hisham Muhammad
f7eea62957 Fix memory leak in case of realloc failure.
Fixes #101.
2017-11-26 16:49:39 -02:00
Hisham Muhammad
1b5073419f Merge branch 'master' of https://github.com/keplerproject/luafilesystem 2017-11-26 16:44:49 -02:00
Stephen E. Baker
fe964e013d Update version in lfs.def (#96)
Version number of current release is 1.7
2017-10-08 17:03:08 -03:00
Dan Church
12d1692f14 Support DESTDIR make install option (#98)
Useful for packagers to specify a build jail to install into.
2017-10-08 17:01:53 -03:00
3 changed files with 14 additions and 8 deletions

View File

@@ -18,8 +18,8 @@ test: lib
LUA_CPATH=./src/?.so lua tests/test.lua
install:
mkdir -p $(LUA_LIBDIR)
cp src/lfs.so $(LUA_LIBDIR)
mkdir -p $(DESTDIR)$(LUA_LIBDIR)
cp src/lfs.so $(DESTDIR)$(LUA_LIBDIR)
clean:
rm -f src/lfs.so $(OBJS)

View File

@@ -186,9 +186,12 @@ static int get_dir (lua_State *L) {
size_t size = LFS_MAXPATHLEN; /* initial buffer size */
int result;
while (1) {
path = realloc(path, size);
if (!path) /* failed to allocate */
return pusherror(L, "get_dir realloc() failed");
char* path2 = realloc(path, size);
if (!path2) /* failed to allocate */ {
result = pusherror(L, "get_dir realloc() failed");
break;
}
path = path2;
if (getcwd(path, size) != NULL) {
/* success, push the path to the Lua stack */
lua_pushstring(L, path);
@@ -860,9 +863,12 @@ static int push_link_target(lua_State *L) {
char *target = NULL;
int tsize, size = 256; /* size = initial buffer capacity */
while (1) {
target = realloc(target, size);
if (!target) /* failed to allocate */
char* target2 = realloc(target, size);
if (!target2) { /* failed to allocate */
free(target);
return 0;
}
target = target2;
tsize = readlink(file, target, size);
if (tsize < 0) { /* a readlink() error occurred */
free(target);

View File

@@ -1,4 +1,4 @@
LIBRARY lfs.dll
VERSION 1.6
VERSION 1.7
EXPORTS
luaopen_lfs