Run closedir(isDir); after checking isDir

This commit is contained in:
RocketRobz 2018-10-19 18:41:54 -06:00
parent 9651648836
commit 013ffe654d

View File

@ -47,6 +47,9 @@ int fcopy(const char *sourcePath, const char *destinationPath)
DIR *isDir = opendir (sourcePath);
if (isDir != NULL) {
closedir(isDir);
// Source path is a directory
chdir(sourcePath);
vector<DirEntry> dirContents;
getDirectoryContents(dirContents);
@ -63,6 +66,9 @@ int fcopy(const char *sourcePath, const char *destinationPath)
chdir ("..");
return 1;
} else {
closedir(isDir);
// Source path is a file
FILE* sourceFile = fopen(sourcePath, "rb");
off_t fsize = 0;
if (sourceFile) {
@ -119,5 +125,4 @@ int fcopy(const char *sourcePath, const char *destinationPath)
return -1;
}
closedir(isDir);
}