summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/virtfsdir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/virtfs/virtfsdir.cpp')
-rw-r--r--src/fs/virtfs/virtfsdir.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/fs/virtfs/virtfsdir.cpp b/src/fs/virtfs/virtfsdir.cpp
index 223b45e1d..902e686c0 100644
--- a/src/fs/virtfs/virtfsdir.cpp
+++ b/src/fs/virtfs/virtfsdir.cpp
@@ -485,13 +485,15 @@ namespace VirtFsDir
if (fstat(fd, &statbuf) == -1)
{
reportAlways("VirtFsDir::fileLength error.");
- return -1;
+ if (fd != FILEHDEFAULT)
+ FILECLOSE(fd);
+ return nullptr;
}
fileSize = static_cast<int>(statbuf.st_size);
#endif // USE_FILE_FOPEN
// Allocate memory and load the file
- char *restrict const buffer = new char[fileSize];
+ char *restrict const buffer = new char[CAST_SIZE(fileSize)];
if (fileSize > 0)
buffer[fileSize - 1] = 0;