diff --git a/Common/ArmCPUDetect.cpp b/Common/ArmCPUDetect.cpp index 36c5e27411..1775df58f6 100644 --- a/Common/ArmCPUDetect.cpp +++ b/Common/ArmCPUDetect.cpp @@ -44,6 +44,8 @@ char *GetCPUString() // INFO_LOG(BOOT, "CPU: %s", cpu_string); break; } + + fclose(fp); return cpu_string; } bool CheckCPUFeature(const char *feature) @@ -69,6 +71,8 @@ bool CheckCPUFeature(const char *feature) token = strtok(NULL, " "); } } + + fclose(fp); return false; } #endif @@ -94,6 +98,8 @@ int GetCoreCount() continue; ++cores; } + + fclose(fp); return cores; #endif } diff --git a/Common/FileUtil.cpp b/Common/FileUtil.cpp index 638f278b0f..d3a8b39a5e 100644 --- a/Common/FileUtil.cpp +++ b/Common/FileUtil.cpp @@ -567,12 +567,24 @@ bool DeleteDirRecursively(const std::string &directory) if (IsDirectory(newPath)) { if (!DeleteDirRecursively(newPath)) + { + #ifndef _WIN32 + closedir(dirp); + #endif + return false; + } } else { if (!File::Delete(newPath)) + { + #ifndef _WIN32 + closedir(dirp); + #endif + return false; + } } #ifdef _WIN32 diff --git a/Common/StringUtil.h b/Common/StringUtil.h index b4282c3533..0b2ca1bd08 100644 --- a/Common/StringUtil.h +++ b/Common/StringUtil.h @@ -42,16 +42,20 @@ static inline int vasprintf(char **rResult, const char *aFormat, va_list aAp) rVal = vsnprintf(result, 16, aFormat, ap); va_end(ap); - if (rVal == -1) return rVal; + if (rVal == -1) + { + free(result); + return rVal; + } else if (rVal >= 16) { - free(result); - result = (char *) malloc(rVal + 1); - if (result == NULL) return -1; + free(result); + result = (char *) malloc(rVal + 1); + if (result == NULL) return -1; - va_copy(ap, aAp); - rVal = vsnprintf(result, rVal + 1, aFormat, aAp); - va_end(ap); + va_copy(ap, aAp); + rVal = vsnprintf(result, rVal + 1, aFormat, aAp); + va_end(ap); } *rResult = result;