Skip to content

Commit

Permalink
Merge branch 'cegli_memory_leak'
Browse files Browse the repository at this point in the history
Fixes #1 and closes #2
memory leak in resolveSubtable and defaultTableResolver

Thanks to Christian Egli for finding the memory leak and providing the patches.
  • Loading branch information
mhameed committed May 21, 2014
2 parents 22b7ecd + 0e8d4e3 commit 713374b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
4 changes: 3 additions & 1 deletion NEWS
Expand Up @@ -7,8 +7,10 @@ liblouis NEWS -- history of user-visible changes. -*- org -*-
** Bug fixes
- Fixed bug to prevent removal of \xffff between largesign rules. This
solves a LibLouisUTDML bug where \xffff is used as a segment delimiter.
_ Fixed a bug in backtranslation, when a letsign was encountered, the
- Fixed a bug in backtranslation, when a letsign was encountered, the
letsign was being applied beyond the element it applied to.
- Fix memory leaks in the default table resolver introduced in the
previous release.

** Braille table improvements
- Fix for Norwegian where letsign is affecting some extra characters
Expand Down
38 changes: 32 additions & 6 deletions liblouis/compileTranslationTable.c
Expand Up @@ -4627,7 +4627,8 @@ resolveSubtable (const char *table, const char *base, const char *searchPath)
char *dir;
int last;
char *cp;
for (dir = strdup (searchPath + 1); ; dir = cp + 1)
char *searchPath_copy = strdup (searchPath + 1);
for (dir = searchPath_copy; ; dir = cp + 1)
{
for (cp = dir; *cp != '\0' && *cp != ','; cp++)
;
Expand All @@ -4636,11 +4637,15 @@ resolveSubtable (const char *table, const char *base, const char *searchPath)
if (dir == cp)
dir = ".";
sprintf (tableFile, "%s%c%s", dir, DIR_SEP, table);
if (stat (tableFile, &info) == 0 && !(info.st_mode & S_IFDIR))
return tableFile;
if (stat (tableFile, &info) == 0 && !(info.st_mode & S_IFDIR))
{
free(searchPath_copy);
return tableFile;
}
if (last)
break;
}
free(searchPath_copy);
}
free (tableFile);
return NULL;
Expand All @@ -4666,6 +4671,7 @@ defaultTableResolver (const char *tableList, const char *base)
char searchPath[MAXSTRING];
char **tableFiles;
char *subTable;
char *tableList_copy;
char *cp;
char *path;
int last;
Expand Down Expand Up @@ -4697,14 +4703,16 @@ defaultTableResolver (const char *tableList, const char *base)

/* Resolve subtables */
k = 0;
for (subTable = strdup (tableList); ; subTable = cp + 1)
tableList_copy = strdup (tableList);
for (subTable = tableList_copy; ; subTable = cp + 1)
{
for (cp = subTable; *cp != '\0' && *cp != ','; cp++);
last = (*cp == '\0');
*cp = '\0';
if (!(tableFiles[k++] = resolveSubtable (subTable, base, searchPath)))
{
lou_logPrint ("Cannot resolve table '%s'", subTable);
free(tableList_copy);
free (tableFiles);
return NULL;
}
Expand All @@ -4713,6 +4721,7 @@ defaultTableResolver (const char *tableList, const char *base)
if (last)
break;
}
free(tableList_copy);
tableFiles[k] = NULL;
return tableFiles;
}
Expand Down Expand Up @@ -4766,7 +4775,19 @@ compileFile (const char *fileName)
return 0;
}

/*
/**
* Free a char** array
*/
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 @@ -4776,6 +4797,7 @@ includeFile (FileInfo * nested, CharsString * includedFile)
int k;
char includeThis[MAXSTRING];
char **tableFiles;
int rv;
for (k = 0; k < includedFile->length; k++)
includeThis[k] = (char) includedFile->chars[k];
includeThis[k] = 0;
Expand All @@ -4788,10 +4810,13 @@ includeFile (FileInfo * nested, CharsString * includedFile)
if (tableFiles[1] != NULL)
{
errorCount++;
free_tablefiles(tableFiles);
lou_logPrint ("Table list not supported in include statement: 'include %s'", includeThis);
return 0;
}
return compileFile (*tableFiles);
rv = compileFile (*tableFiles);
free_tablefiles(tableFiles);
return rv;
}

/**
Expand Down Expand Up @@ -4836,6 +4861,7 @@ compileTranslationTable (const char *tableList)

/* Clean up after compiling files */
cleanup:
free_tablefiles(tableFiles);
if (characterClasses)
deallocateCharacterClasses ();
if (ruleNames)
Expand Down

0 comments on commit 713374b

Please sign in to comment.