From 828999cae3e0b46d4e4512abdceac9dfccd49244 Mon Sep 17 00:00:00 2001 From: Joel Goguen Date: Sun, 19 Apr 2026 22:25:46 -0400 Subject: [PATCH] fix: free parser on error Found while looking into #105 but the opposite problem. This frees the parser after an error has occurred and early return. --- lib/Epub/Epub/parsers/ContainerParser.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Epub/Epub/parsers/ContainerParser.cpp b/lib/Epub/Epub/parsers/ContainerParser.cpp index aa7a92a0..82adb9ac 100644 --- a/lib/Epub/Epub/parsers/ContainerParser.cpp +++ b/lib/Epub/Epub/parsers/ContainerParser.cpp @@ -35,6 +35,8 @@ size_t ContainerParser::write(const uint8_t* buffer, const size_t size) { void* const buf = XML_GetBuffer(parser, 1024); if (!buf) { LOG_DBG("CTR", "Couldn't allocate buffer"); + XML_ParserFree(parser); + parser = nullptr; return 0; } @@ -43,6 +45,8 @@ size_t ContainerParser::write(const uint8_t* buffer, const size_t size) { if (XML_ParseBuffer(parser, static_cast(toRead), remainingSize == toRead) == XML_STATUS_ERROR) { LOG_ERR("CTR", "Parse error: %s", XML_ErrorString(XML_GetErrorCode(parser))); + XML_ParserFree(parser); + parser = nullptr; return 0; }