Addressed comments on malloc

This commit is contained in:
Sen Huang 2019-10-02 18:34:42 -04:00
parent c763457e0a
commit 4dc604cab8
3 changed files with 15 additions and 8 deletions

View File

@ -1453,9 +1453,6 @@ int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs, const char** inFileN
} }
FIO_freeCResources(ress);
if (dstFileNamesTable)
UTIL_freeDestinationFilenameTable(dstFileNamesTable, nbFiles);
return error;
}
@ -2276,9 +2273,6 @@ FIO_decompressMultipleFilenames(FIO_prefs_t* const prefs,
}
FIO_freeDResources(ress);
if (outDirName)
UTIL_freeDestinationFilenameTable(dstFileNamesTable, nbFiles);
return error;
}

View File

@ -140,14 +140,22 @@ void UTIL_createDestinationDirTable(char** dstFilenameTable, const char** filena
filenameBegin = strrchr(filenameTable[u], c[0]);
if (filenameBegin == NULL) {
filename = (char*) malloc((strlen(filenameTable[u])+1) * sizeof(char));
if (!filename) {
UTIL_DISPLAYLEVEL(1, "Unable to allocate space for filename str\n");
continue;
}
strcpy(filename, filenameTable[u]);
} else {
filename = (char*) malloc((strlen(filenameBegin+1)) * sizeof(char));
filename = (char*) malloc((strlen(filenameBegin+1)+1) * sizeof(char));
if (!filename) {
UTIL_DISPLAYLEVEL(1, "Unable to allocate space for filename str\n");
continue;
}
strcpy(filename, filenameBegin+1);
}
finalPathLen += strlen(filename);
dstFilenameTable[u] = (char*) malloc((finalPathLen+2) * sizeof(char));
dstFilenameTable[u] = (char*) malloc((finalPathLen+3) * sizeof(char));
if (!dstFilenameTable[u]) {
UTIL_DISPLAYLEVEL(1, "Unable to allocate space for file destination str\n");
free(filename);

View File

@ -1192,6 +1192,9 @@ int main(int argCount, const char* argv[])
operationResult = FIO_compressFilename(prefs, outFileName, filenameTable[0], dictFileName, cLevel, compressionParams);
else
operationResult = FIO_compressMultipleFilenames(prefs, filenameTable, outDirName, dstFilenameTable, filenameIdx, outFileName, suffix, dictFileName, cLevel, compressionParams);
if (dstFilenameTable)
UTIL_freeDestinationFilenameTable(dstFilenameTable, filenameIdx);
#else
(void)suffix; (void)adapt; (void)rsyncable; (void)ultra; (void)cLevel; (void)ldmFlag; (void)literalCompressionMode; (void)targetCBlockSize; (void)streamSrcSize; (void)srcSizeHint; /* not used when ZSTD_NOCOMPRESS set */
DISPLAY("Compression not supported \n");
@ -1224,6 +1227,8 @@ int main(int argCount, const char* argv[])
operationResult = FIO_decompressFilename(prefs, outFileName, filenameTable[0], dictFileName);
else
operationResult = FIO_decompressMultipleFilenames(prefs, filenameTable, filenameIdx, outDirName, dstFilenameTable, outFileName, dictFileName);
if (dstFilenameTable)
UTIL_freeDestinationFilenameTable(dstFilenameTable, filenameIdx);
#else
DISPLAY("Decompression not supported \n");
#endif