fixing memory leak issue and removing c90 issue
This commit is contained in:
@@ -308,6 +308,7 @@ void UTIL_freeFileNamesTable(FileNamesTable* table) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static size_t getTotalTableSize(FileNamesTable* table) {
|
static size_t getTotalTableSize(FileNamesTable* table) {
|
||||||
|
UTIL_DISPLAY("[TRACE] getTotalTableSize \n");
|
||||||
size_t i = 0, totalSize = 0;
|
size_t i = 0, totalSize = 0;
|
||||||
for(i = 0 ; i < table->tableSize && table->fileNames[i] ; ++i) {
|
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 */
|
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));
|
FileNamesTable* newTable = (FileNamesTable*) malloc(sizeof(FileNamesTable));
|
||||||
|
|
||||||
|
UTIL_DISPLAY("[TRACE] newTable created\n");
|
||||||
|
|
||||||
if(!newTable) {
|
if(!newTable) {
|
||||||
UTIL_DISPLAYLEVEL(1, "[ERROR][UTIL_concatenateTwoTables] Can't create new table for concatenation output.\n");
|
UTIL_DISPLAYLEVEL(1, "[ERROR][UTIL_concatenateTwoTables] Can't create new table for concatenation output.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
+7
-9
@@ -589,7 +589,7 @@ int main(int argCount, const char* argv[])
|
|||||||
const char** filenameTable = (const char**)malloc(filenameTableSize * sizeof(const char*)); /* argCount >= 1 */
|
const char** filenameTable = (const char**)malloc(filenameTableSize * sizeof(const char*)); /* argCount >= 1 */
|
||||||
FileNamesTable* extendedTable = NULL;
|
FileNamesTable* extendedTable = NULL;
|
||||||
FileNamesTable* concatenatedTables = NULL;
|
FileNamesTable* concatenatedTables = NULL;
|
||||||
FileNamesTable* curTable = (FileNamesTable*) malloc(sizeof(FileNamesTable));
|
FileNamesTable* curTable = NULL;
|
||||||
char* tableBuf = NULL;
|
char* tableBuf = NULL;
|
||||||
unsigned filenameIdx = 0;
|
unsigned filenameIdx = 0;
|
||||||
const char* programName = argv[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 */
|
(void)memLimit; /* not used when ZSTD_NODECOMPRESS set */
|
||||||
if (filenameTable==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); }
|
if (filenameTable==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); }
|
||||||
filenameTable[0] = stdinmark;
|
filenameTable[0] = stdinmark;
|
||||||
curTable->fileNames = filenameTable;
|
|
||||||
curTable->tableSize = filenameTableSize;
|
|
||||||
curTable->buf = tableBuf;
|
|
||||||
g_displayOut = stderr;
|
g_displayOut = stderr;
|
||||||
cLevel = init_cLevel();
|
cLevel = init_cLevel();
|
||||||
programName = lastNameFromPath(programName);
|
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] call read function is finished\n");
|
||||||
DISPLAYLEVEL(4, "[TRACE] extendedFileNamesTable:\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] call concatenation function\n");
|
||||||
DISPLAYLEVEL(4, "[TRACE] filenameidx: %d\n", filenameIdx);
|
DISPLAYLEVEL(4, "[TRACE] filenameidx: %d\n", filenameIdx);
|
||||||
|
|
||||||
for(i = filenameIdx; i < filenameTableSize ; ++i)
|
// unsigned i = 0;
|
||||||
filenameTable[i] = NULL;
|
// for(i = filenameIdx; i < filenameTableSize ; ++i)
|
||||||
|
filenameTable[filenameIdx] = NULL; // marking end of table
|
||||||
|
|
||||||
|
|
||||||
|
curTable = (FileNamesTable*) malloc(sizeof(FileNamesTable));
|
||||||
|
|
||||||
if(!curTable) {
|
if(!curTable) {
|
||||||
UTIL_freeFileNamesTable(extendedTable);
|
UTIL_freeFileNamesTable(extendedTable);
|
||||||
|
|||||||
Reference in New Issue
Block a user