Fix some missing frees, null dereferences and missing initialisation picked up by clang-analyzer

This commit is contained in:
nvx committed 2024-01-16 00:22:53 +10:00
1 parent 5db2276602
commit d2d6f80d11
11 files changed
+24 -15

No files matched your search

+3 -2
View File
@@ -1333,11 +1333,12 @@ static int l_cwd(lua_State *L) {
while (GetCurrentDir(cwd, path_len) == NULL) {
if (errno == ERANGE) { // Need bigger buffer
path_len += 10; // if buffer was too small add 10 characters and try again
cwd = realloc(cwd, path_len);
if (cwd == NULL) {
char* cwdNew = realloc(cwd, path_len);
if (cwdNew == NULL) {
free(cwd);
return returnToLuaWithError(L, "Failed to allocate memory");
}
cwd = cwdNew;
} else {
free(cwd);
return returnToLuaWithError(L, "Failed to get current working directory");