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);
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
}

View File

@ -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

View File

@ -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;