From 01dfd14ecf3243d74e7e6acf49bf613fb1f0cfeb Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Sun, 26 May 2013 19:26:46 +0200 Subject: [PATCH] xml_parser: Prevent memory leak during parse error. --- src/xml_parser_filelists.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/xml_parser_filelists.c b/src/xml_parser_filelists.c index 9fcd438..dee3d39 100644 --- a/src/xml_parser_filelists.c +++ b/src/xml_parser_filelists.c @@ -347,6 +347,16 @@ cr_xml_parse_filelists(const char *path, if (pd->err) g_propagate_error(err, pd->err); + if (ret != CRE_OK && newpkgcb == cr_newpkgcb) { + // Prevent memory leak when the parsing is interrupted by an error. + // If a new package object was created by the cr_newpkgcb then + // is obvious that there is no other reference to the package + // except of the parser reference in pd->pkg. + // If a caller supplied its own newpkgcb, then the freeing + // of the currently parsed package is the caller responsibility. + cr_package_free(pd->pkg); + } + msgs = cr_xml_parser_data_free(pd); XML_ParserFree(parser); cr_close(f); -- 2.7.4