diff options
-rw-r--r-- | src/lfs.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -186,9 +186,12 @@ static int get_dir (lua_State *L) { | |||
186 | size_t size = LFS_MAXPATHLEN; /* initial buffer size */ | 186 | size_t size = LFS_MAXPATHLEN; /* initial buffer size */ |
187 | int result; | 187 | int result; |
188 | while (1) { | 188 | while (1) { |
189 | path = realloc(path, size); | 189 | char* path2 = realloc(path, size); |
190 | if (!path) /* failed to allocate */ | 190 | if (!path2) /* failed to allocate */ { |
191 | return pusherror(L, "get_dir realloc() failed"); | 191 | result = pusherror(L, "get_dir realloc() failed"); |
192 | break; | ||
193 | } | ||
194 | path = path2; | ||
192 | if (getcwd(path, size) != NULL) { | 195 | if (getcwd(path, size) != NULL) { |
193 | /* success, push the path to the Lua stack */ | 196 | /* success, push the path to the Lua stack */ |
194 | lua_pushstring(L, path); | 197 | lua_pushstring(L, path); |
@@ -860,9 +863,12 @@ static int push_link_target(lua_State *L) { | |||
860 | char *target = NULL; | 863 | char *target = NULL; |
861 | int tsize, size = 256; /* size = initial buffer capacity */ | 864 | int tsize, size = 256; /* size = initial buffer capacity */ |
862 | while (1) { | 865 | while (1) { |
863 | target = realloc(target, size); | 866 | char* target2 = realloc(target, size); |
864 | if (!target) /* failed to allocate */ | 867 | if (!target2) { /* failed to allocate */ |
868 | free(target); | ||
865 | return 0; | 869 | return 0; |
870 | } | ||
871 | target = target2; | ||
866 | tsize = readlink(file, target, size); | 872 | tsize = readlink(file, target, size); |
867 | if (tsize < 0) { /* a readlink() error occurred */ | 873 | if (tsize < 0) { /* a readlink() error occurred */ |
868 | free(target); | 874 | free(target); |