kill memory leaks, cleanup, fix some dumb bugs
This commit is contained in:
parent
6beb3c0159
commit
a9c807a948
@ -1390,10 +1390,8 @@ FIO_determineCompressedName(const char* srcFileName, const char* suffix)
|
||||
{
|
||||
static size_t dfnbCapacity = 0;
|
||||
static char* dstFileNameBuffer = NULL; /* using static allocation : this function cannot be multi-threaded */
|
||||
|
||||
size_t const sfnSize = strlen(srcFileName);
|
||||
size_t const suffixSize = strlen(suffix);
|
||||
|
||||
if (dfnbCapacity <= sfnSize+suffixSize+1) {
|
||||
/* resize buffer for dstName */
|
||||
free(dstFileNameBuffer);
|
||||
@ -1405,7 +1403,6 @@ FIO_determineCompressedName(const char* srcFileName, const char* suffix)
|
||||
assert(dstFileNameBuffer != NULL);
|
||||
memcpy(dstFileNameBuffer, srcFileName, sfnSize);
|
||||
memcpy(dstFileNameBuffer+sfnSize, suffix, suffixSize+1 /* Include terminating null */);
|
||||
|
||||
return dstFileNameBuffer;
|
||||
}
|
||||
|
||||
@ -1456,7 +1453,7 @@ int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs, const char** inFileN
|
||||
} }
|
||||
|
||||
FIO_freeCResources(ress);
|
||||
/*UTIL_freeDestinationFilenameTable(dstFileNamesTable, nbFiles);*/
|
||||
UTIL_freeDestinationFilenameTable(dstFileNamesTable, nbFiles);
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -2277,7 +2274,7 @@ FIO_decompressMultipleFilenames(FIO_prefs_t* const prefs,
|
||||
}
|
||||
|
||||
FIO_freeDResources(ress);
|
||||
/* UTIL_freeDestinationFilenameTable(dstFileNamesTable, nbFiles); */
|
||||
UTIL_freeDestinationFilenameTable(dstFileNamesTable, nbFiles);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -87,11 +87,12 @@ U32 UTIL_isDirectory(const char* infilename)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int UTIL_createDir(const char* outDirName) {
|
||||
if (UTIL_isDirectory(outDirName)) {
|
||||
return 0; /* no need to create if directory already exists */
|
||||
}
|
||||
int UTIL_createDir(const char* outDirName)
|
||||
{
|
||||
int r;
|
||||
if (UTIL_isDirectory(outDirName))
|
||||
return 0; /* no need to create if directory already exists */
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
r = _mkdir(outDirName);
|
||||
if (r || !UTIL_isDirectory(outDirName)) return 1;
|
||||
@ -108,20 +109,17 @@ void UTIL_createDestinationDirTable(const char** filenameTable, unsigned nbFiles
|
||||
unsigned u;
|
||||
char c;
|
||||
c = '/';
|
||||
printf("NBFILE: %u\n", nbFiles);
|
||||
|
||||
/* duplicate source file table */
|
||||
for (u = 0; u < nbFiles; ++u) {
|
||||
char* filename;
|
||||
char* finalPath;
|
||||
size_t finalPathLen;
|
||||
finalPathLen = strlen(outDirName);
|
||||
filename = strrchr(filenameTable[u], c); /* filename is the last bit of string after '/' */
|
||||
finalPathLen += strlen(filename);
|
||||
dstFilenameTable[u] = (char*) malloc(finalPathLen * sizeof(char) + 1);
|
||||
dstFilenameTable[u] = (char*) malloc((finalPathLen+5) * sizeof(char)); /* extra 1 bit for \0, extra 4 for .zst if compressing*/
|
||||
strcpy(dstFilenameTable[u], outDirName);
|
||||
strcat(dstFilenameTable[u], filename);
|
||||
printf("%s %s\n", filenameTable[u], dstFilenameTable[u]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -585,7 +585,7 @@ int main(int argCount, const char* argv[])
|
||||
unsigned recursive = 0;
|
||||
unsigned memLimit = 0;
|
||||
const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */
|
||||
char** dstFilenameTable = (char**)malloc(argCount * sizeof(char*));
|
||||
char** dstFilenameTable;
|
||||
unsigned filenameIdx = 0;
|
||||
const char* programName = argv[0];
|
||||
const char* outFileName = NULL;
|
||||
@ -1177,8 +1177,10 @@ int main(int argCount, const char* argv[])
|
||||
if (adaptMin > cLevel) cLevel = adaptMin;
|
||||
if (adaptMax < cLevel) cLevel = adaptMax;
|
||||
|
||||
if (outDirName)
|
||||
if (outDirName) {
|
||||
dstFilenameTable = (char**)malloc(filenameIdx * sizeof(char*));
|
||||
FIO_processMultipleFilenameDestinationDir(dstFilenameTable, filenameTable, filenameIdx, outFileName, outDirName);
|
||||
}
|
||||
|
||||
if ((filenameIdx==1) && outFileName)
|
||||
operationResult = FIO_compressFilename(prefs, outFileName, filenameTable[0], dictFileName, cLevel, compressionParams);
|
||||
@ -1199,9 +1201,10 @@ int main(int argCount, const char* argv[])
|
||||
}
|
||||
FIO_setMemLimit(prefs, memLimit);
|
||||
|
||||
if (outDirName)
|
||||
if (outDirName) {
|
||||
dstFilenameTable = (char**)malloc(filenameIdx * sizeof(char*));
|
||||
FIO_processMultipleFilenameDestinationDir(dstFilenameTable, filenameTable, filenameIdx, outFileName, outDirName);
|
||||
|
||||
}
|
||||
if (filenameIdx==1 && outFileName)
|
||||
operationResult = FIO_decompressFilename(prefs, outFileName, filenameTable[0], dictFileName);
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user