sfnt2fnt: Remove output file on failure.
diff --git a/tools/sfnt2fnt.c b/tools/sfnt2fnt.c
index 6b9f341..63e5b7a 100644
--- a/tools/sfnt2fnt.c
+++ b/tools/sfnt2fnt.c
@@ -55,6 +55,8 @@
 
 #include "poppack.h"
 
+static const char *output_name;
+
 static void usage(char **argv)
 {
     fprintf(stderr, "%s foo.ttf ppem enc dpi def_char avg_width\n", argv[0]);
@@ -65,6 +67,12 @@
 #define __attribute__(X)
 #endif
 
+/* atexit handler to cleanup files */
+static void cleanup(void)
+{
+    if (output_name) unlink( output_name );
+}
+
 static void error(const char *s, ...) __attribute__((format (printf, 1, 2)));
 
 static void error(const char *s, ...)
@@ -377,10 +385,13 @@
 
     sprintf(output, "%s-%d-%d-%d.fnt", name, enc, dpi, ppem);
 
+    atexit( cleanup );
     fp = fopen(output, "w");
+    output_name = output;
 
     fill_fontinfo(face, enc, fp, dpi, def_char, avg_width);
     fclose(fp);
+    output_name = NULL;
     exit(0);
 }