From c763457e0a4d70b6912bc14c5908a38c3239a0bf Mon Sep 17 00:00:00 2001 From: Sen Huang Date: Wed, 2 Oct 2019 15:30:24 -0400 Subject: [PATCH] Static analyze fix --- programs/util.c | 7 +++---- programs/util.h | 2 +- programs/zstdcli.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/programs/util.c b/programs/util.c index aa769567..83fa70ba 100644 --- a/programs/util.c +++ b/programs/util.c @@ -122,7 +122,7 @@ int UTIL_checkFilenameCollisions(char** dstFilenameTable, unsigned nbFiles) { } void UTIL_createDestinationDirTable(char** dstFilenameTable, const char** filenameTable, - const unsigned nbFiles, const char* outDirName, const int compressing) + const unsigned nbFiles, const char* outDirName) { unsigned u; const char* c; @@ -147,11 +147,10 @@ void UTIL_createDestinationDirTable(char** dstFilenameTable, const char** filena } finalPathLen += strlen(filename); - dstFilenameTable[u] = compressing ? - (char*) malloc((finalPathLen+6) * sizeof(char)) /* 4 more bytes for .zst suffix */ - : (char*) malloc((finalPathLen+2) * sizeof(char)); + dstFilenameTable[u] = (char*) malloc((finalPathLen+2) * sizeof(char)); if (!dstFilenameTable[u]) { UTIL_DISPLAYLEVEL(1, "Unable to allocate space for file destination str\n"); + free(filename); continue; } diff --git a/programs/util.h b/programs/util.h index e90b251d..558e7a9c 100644 --- a/programs/util.h +++ b/programs/util.h @@ -133,7 +133,7 @@ int UTIL_compareStr(const void *p1, const void *p2); int UTIL_checkFilenameCollisions(char** dstFilenameTable, unsigned nbFiles); /* Populates dstFilenameTable using outDirName concatenated with entries from filenameTable */ void UTIL_createDestinationDirTable(char** dstFilenameTable, const char** filenameTable, const unsigned nbFiles, - const char* outDirName, const int compressing); + const char* outDirName); void UTIL_freeDestinationFilenameTable(char** dstDirTable, unsigned nbFiles); U32 UTIL_isLink(const char* infilename); diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 63e71e7e..d9e1be66 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -1179,7 +1179,7 @@ int main(int argCount, const char* argv[]) if (UTIL_isDirectory(outDirName)) { DISPLAY("Output of files will be in directory: %s\n", outDirName); dstFilenameTable = (char**)malloc(filenameIdx * sizeof(char*)); - UTIL_createDestinationDirTable(dstFilenameTable, filenameTable, filenameIdx, outDirName, 1); + UTIL_createDestinationDirTable(dstFilenameTable, filenameTable, filenameIdx, outDirName); } else { DISPLAY("%s is not a directory!\n", outDirName); CLEAN_RETURN(1); @@ -1211,7 +1211,7 @@ int main(int argCount, const char* argv[]) if (UTIL_isDirectory(outDirName)) { DISPLAY("Output of files will be in directory: %s\n", outDirName); dstFilenameTable = (char**)malloc(filenameIdx * sizeof(char*)); - UTIL_createDestinationDirTable(dstFilenameTable, filenameTable, filenameIdx, outDirName, 1); + UTIL_createDestinationDirTable(dstFilenameTable, filenameTable, filenameIdx, outDirName); } else { DISPLAY("%s is not a directory!\n", outDirName); CLEAN_RETURN(1);