diff --git a/tests/runtest.c b/tests/runtest.c
index ce6e78807f2118d9ae39b3a62b4a53547e834dfe_dGVzdHMvcnVudGVzdC5j..075286e51f9a6312927756af4357ad251062f717_dGVzdHMvcnVudGVzdC5j 100644
--- a/tests/runtest.c
+++ b/tests/runtest.c
@@ -582,7 +582,7 @@
 static int
 xsltTest(const char *filename, int options) {
     xsltStylesheetPtr style;
-    xmlDocPtr styleDoc, doc, outDoc;
+    xmlDocPtr styleDoc, doc = NULL, outDoc;
     xmlChar *out = NULL;
     const char *outSuffix, *errSuffix;
     char *docFilename, *outFilename, *errFilename;
@@ -602,6 +602,7 @@
     } else {
         docFilename = changeSuffix(filename, ".xml");
         if (!checkTestFile(docFilename)) {
+            xmlFreeDoc(styleDoc);
             goto out;
         }
         style = xsltParseStylesheetDoc(styleDoc);
@@ -632,6 +633,7 @@
         }
         xsltFreeStylesheet(style);
     }
+    xmlFreeDoc(doc);
 
     outFilename = changeSuffix(filename, outSuffix);
     res = compareFileMem(outFilename, (char *) out, outSize);