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