Skip to content

Commit

Permalink
Do not free NULL
Browse files Browse the repository at this point in the history
When tableFiles is NULL the macro tried to free it anyway. Change the
macro into a function and test for NULL before freeing.

This fixes a segfault in the tests.
  • Loading branch information
egli committed May 21, 2014
1 parent 9cec866 commit a53250d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions liblouis/compileTranslationTable.c
Expand Up @@ -4776,14 +4776,16 @@ compileFile (const char *fileName)
}

/**
* Macro to free a char** array
* Free a char** array
*/
#define free_tablefiles(tables) { \
char **table; \
for (table = tables; *table; table++) \
free(*table); \
free(tables); \
}
static void
free_tablefiles(char **tables) {
char **table;
if (!tables) return;
for (table = tables; *table; table++)
free(*table);
free(tables);
}

/**
* Implement include opcode
Expand All @@ -4808,7 +4810,7 @@ includeFile (FileInfo * nested, CharsString * includedFile)
if (tableFiles[1] != NULL)
{
errorCount++;
free_tablefiles(tableFiles)
free_tablefiles(tableFiles);
lou_logPrint ("Table list not supported in include statement: 'include %s'", includeThis);
return 0;
}
Expand Down

0 comments on commit a53250d

Please sign in to comment.