libyang BUGFIX memory leaks

reported by coverity
diff --git a/src/printer.c b/src/printer.c
index a4905c8..b324030 100644
--- a/src/printer.c
+++ b/src/printer.c
@@ -394,6 +394,8 @@
     (*out)->method.fpath.f = fopen(filepath, "w");
     if (!(*out)->method.fpath.f) {
         LOGERR(NULL, LY_ESYS, "Failed to open file \"%s\" (%s).", filepath, strerror(errno));
+        free(*out);
+        *out = NULL;
         return LY_ESYS;
     }
     (*out)->method.fpath.filepath = strdup(filepath);