From: Ahmed Abdellah Date: Thu, 24 Oct 2019 08:39:16 +0000 (+0100) Subject: fixing memory leak issue and removing c90 issue X-Git-Tag: v1.4.5^2~141^2~35^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f43e45954ff337f5e9e74686b7b2c66581506388;p=thirdparty%2Fzstd.git fixing memory leak issue and removing c90 issue --- diff --git a/programs/util.c b/programs/util.c index e28e4a96b..7da11e2f6 100644 --- a/programs/util.c +++ b/programs/util.c @@ -308,6 +308,7 @@ void UTIL_freeFileNamesTable(FileNamesTable* table) { } static size_t getTotalTableSize(FileNamesTable* table) { + UTIL_DISPLAY("[TRACE] getTotalTableSize \n"); size_t i = 0, totalSize = 0; for(i = 0 ; i < table->tableSize && table->fileNames[i] ; ++i) { totalSize += strlen(table->fileNames[i]) + 1; /* +1 to add '\0' at the end of each fileName */ @@ -324,6 +325,8 @@ UTIL_concatenateTwoTables(FileNamesTable* table1, FileNamesTable* table2) { FileNamesTable* newTable = (FileNamesTable*) malloc(sizeof(FileNamesTable)); + UTIL_DISPLAY("[TRACE] newTable created\n"); + if(!newTable) { UTIL_DISPLAYLEVEL(1, "[ERROR][UTIL_concatenateTwoTables] Can't create new table for concatenation output.\n"); return NULL; diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 9a05cf72c..43d496c93 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -589,7 +589,7 @@ int main(int argCount, const char* argv[]) const char** filenameTable = (const char**)malloc(filenameTableSize * sizeof(const char*)); /* argCount >= 1 */ FileNamesTable* extendedTable = NULL; FileNamesTable* concatenatedTables = NULL; - FileNamesTable* curTable = (FileNamesTable*) malloc(sizeof(FileNamesTable)); + FileNamesTable* curTable = NULL; char* tableBuf = NULL; unsigned filenameIdx = 0; const char* programName = argv[0]; @@ -625,9 +625,6 @@ int main(int argCount, const char* argv[]) (void)memLimit; /* not used when ZSTD_NODECOMPRESS set */ if (filenameTable==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); } filenameTable[0] = stdinmark; - curTable->fileNames = filenameTable; - curTable->tableSize = filenameTableSize; - curTable->buf = tableBuf; g_displayOut = stderr; cLevel = init_cLevel(); programName = lastNameFromPath(programName); @@ -823,15 +820,16 @@ int main(int argCount, const char* argv[]) DISPLAYLEVEL(4, "[TRACE] call read function is finished\n"); DISPLAYLEVEL(4, "[TRACE] extendedFileNamesTable:\n"); - unsigned i; - for(i = 0; i < extendedTable->tableSize; ++i) - printf("%s\n",extendedTable->fileNames[i]); DISPLAYLEVEL(4, "[TRACE] call concatenation function\n"); DISPLAYLEVEL(4, "[TRACE] filenameidx: %d\n", filenameIdx); - for(i = filenameIdx; i < filenameTableSize ; ++i) - filenameTable[i] = NULL; + // unsigned i = 0; + // for(i = filenameIdx; i < filenameTableSize ; ++i) + filenameTable[filenameIdx] = NULL; // marking end of table + + + curTable = (FileNamesTable*) malloc(sizeof(FileNamesTable)); if(!curTable) { UTIL_freeFileNamesTable(extendedTable);