Terminate decode at end of string and fix mem leak

Seems that we have to NULL terminate the buffer for
xmlStringLenDecodeEntitites() as otherwise we might end up having extra
data at the end of returned buffer.  (Somehow the length parameter is
not respected always, even if it is the proper size returned by the
zip_fread() - header_skip).

Also free the buffer returned by xmlStringLenDecodeEntitites().

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Miika Turkia 2013-03-17 07:12:23 +02:00 committed by Dirk Hohndel
parent 38d224a335
commit a094b2b88a
2 changed files with 4 additions and 0 deletions

1
file.c
View file

@ -72,6 +72,7 @@ static void zip_read(struct zip_file *file, GError **error, const char *filename
size = read * 3 / 2;
mem = realloc(mem, size);
}
mem[read] = 0;
parse_xml_buffer(filename, mem, read, &dive_table, error);
free(mem);
}

View file

@ -1562,6 +1562,9 @@ void parse_xml_buffer(const char *url, const char *buffer, int size,
target_table = table;
doc = xmlReadMemory(res, strlen(res), url, NULL, 0);
if (res != buffer)
free((char *)res);
if (!doc) {
fprintf(stderr, _("Failed to parse '%s'.\n"), url);
parser_error(error, _("Failed to parse '%s'"), url);