Fix some resource leaks/memory leaks.

This commit is contained in:
Lioncash 2013-01-25 13:00:50 -05:00
parent 4c313e31ac
commit b897309eaf
3 changed files with 29 additions and 7 deletions

View File

@ -44,6 +44,8 @@ char *GetCPUString()
// INFO_LOG(BOOT, "CPU: %s", cpu_string); // INFO_LOG(BOOT, "CPU: %s", cpu_string);
break; break;
} }
fclose(fp);
return cpu_string; return cpu_string;
} }
bool CheckCPUFeature(const char *feature) bool CheckCPUFeature(const char *feature)
@ -69,6 +71,8 @@ bool CheckCPUFeature(const char *feature)
token = strtok(NULL, " "); token = strtok(NULL, " ");
} }
} }
fclose(fp);
return false; return false;
} }
#endif #endif
@ -94,6 +98,8 @@ int GetCoreCount()
continue; continue;
++cores; ++cores;
} }
fclose(fp);
return cores; return cores;
#endif #endif
} }

View File

@ -567,12 +567,24 @@ bool DeleteDirRecursively(const std::string &directory)
if (IsDirectory(newPath)) if (IsDirectory(newPath))
{ {
if (!DeleteDirRecursively(newPath)) if (!DeleteDirRecursively(newPath))
{
#ifndef _WIN32
closedir(dirp);
#endif
return false; return false;
}
} }
else else
{ {
if (!File::Delete(newPath)) if (!File::Delete(newPath))
{
#ifndef _WIN32
closedir(dirp);
#endif
return false; return false;
}
} }
#ifdef _WIN32 #ifdef _WIN32

View File

@ -42,16 +42,20 @@ static inline int vasprintf(char **rResult, const char *aFormat, va_list aAp)
rVal = vsnprintf(result, 16, aFormat, ap); rVal = vsnprintf(result, 16, aFormat, ap);
va_end(ap); va_end(ap);
if (rVal == -1) return rVal; if (rVal == -1)
{
free(result);
return rVal;
}
else if (rVal >= 16) else if (rVal >= 16)
{ {
free(result); free(result);
result = (char *) malloc(rVal + 1); result = (char *) malloc(rVal + 1);
if (result == NULL) return -1; if (result == NULL) return -1;
va_copy(ap, aAp); va_copy(ap, aAp);
rVal = vsnprintf(result, rVal + 1, aFormat, aAp); rVal = vsnprintf(result, rVal + 1, aFormat, aAp);
va_end(ap); va_end(ap);
} }
*rResult = result; *rResult = result;