--- elementtidy-1.0.orig/_elementtidy.c
+++ elementtidy-1.0/_elementtidy.c
@@ -112,16 +112,16 @@
         goto error;
     }
·
-    tidyBufFree(&out);
-    tidyBufFree(&err);
+    if (out.allocator) tidyBufFree(&out);
+    if (err.allocator) tidyBufFree(&err);
·
     tidyRelease(doc);
·
     return Py_BuildValue("NN", pyout, pyerr);
·
   error:
-    tidyBufFree(&out);
-    tidyBufFree(&err);
+    if (err.allocator) tidyBufFree(&out);
+    if (err.allocator) tidyBufFree(&err);
·
     tidyRelease(doc);

