fixed memory leak reported by bryongloden
This commit is contained in:
+15
-3
@@ -199,6 +199,18 @@ UTIL_STATIC U32 UTIL_isDirectory(const char* infilename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A modified version of realloc().
|
||||||
|
* If UTIL_realloc() fails the original block is freed.
|
||||||
|
*/
|
||||||
|
UTIL_STATIC void *UTIL_realloc(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
void *newptr = realloc(ptr, size);
|
||||||
|
if (newptr) return newptr;
|
||||||
|
free(ptr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# define UTIL_HAS_CREATEFILELIST
|
# define UTIL_HAS_CREATEFILELIST
|
||||||
@@ -245,7 +257,7 @@ UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_
|
|||||||
else if ((cFile.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)) {
|
else if ((cFile.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)) {
|
||||||
if (*bufStart + *pos + pathLength >= *bufEnd) {
|
if (*bufStart + *pos + pathLength >= *bufEnd) {
|
||||||
ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
|
ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
|
||||||
*bufStart = (char*)realloc(*bufStart, newListSize);
|
*bufStart = (char*)UTIL_realloc(*bufStart, newListSize);
|
||||||
*bufEnd = *bufStart + newListSize;
|
*bufEnd = *bufStart + newListSize;
|
||||||
if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; }
|
if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; }
|
||||||
}
|
}
|
||||||
@@ -299,7 +311,7 @@ UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_
|
|||||||
} else {
|
} else {
|
||||||
if (*bufStart + *pos + pathLength >= *bufEnd) {
|
if (*bufStart + *pos + pathLength >= *bufEnd) {
|
||||||
ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
|
ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
|
||||||
*bufStart = (char*)realloc(*bufStart, newListSize);
|
*bufStart = (char*)UTIL_realloc(*bufStart, newListSize);
|
||||||
*bufEnd = *bufStart + newListSize;
|
*bufEnd = *bufStart + newListSize;
|
||||||
if (*bufStart == NULL) { free(path); closedir(dir); return 0; }
|
if (*bufStart == NULL) { free(path); closedir(dir); return 0; }
|
||||||
}
|
}
|
||||||
@@ -355,7 +367,7 @@ UTIL_STATIC const char** UTIL_createFileList(const char **inputNames, unsigned i
|
|||||||
size_t len = strlen(inputNames[i]);
|
size_t len = strlen(inputNames[i]);
|
||||||
if (buf + pos + len >= bufend) {
|
if (buf + pos + len >= bufend) {
|
||||||
ptrdiff_t newListSize = (bufend - buf) + LIST_SIZE_INCREASE;
|
ptrdiff_t newListSize = (bufend - buf) + LIST_SIZE_INCREASE;
|
||||||
buf = (char*)realloc(buf, newListSize);
|
buf = (char*)UTIL_realloc(buf, newListSize);
|
||||||
bufend = buf + newListSize;
|
bufend = buf + newListSize;
|
||||||
if (!buf) return NULL;
|
if (!buf) return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user