diff --git a/HTMLparser.c b/HTMLparser.c
index 9769ad5b..ebf2641f 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -5197,6 +5197,7 @@ htmlCreateMemoryParserCtxt(const char *buffer, int size) {
input = xmlNewInputStream(ctxt);
if (input == NULL) {
+ xmlFreeParserInputBuffer(buf);
xmlFreeParserCtxt(ctxt);
return(NULL);
}