Close and remove the temporary file if vcedit_write() fails.
authorTilman Sauerbeck <tilman@code-monkey.de>
Fri, 18 Aug 2006 13:45:19 +0000 (15:45 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Wed, 23 Aug 2006 17:39:15 +0000 (19:39 +0200)
ext/vcedit.c

index cf63e7487217c7a36fcb479590328488928c7c63..38ecb9f9d384818c84df6a0e96b85274fdd34767 100644 (file)
@@ -403,6 +403,7 @@ vcedit_write (vcedit_state *s)
        ogg_int64_t granpos = 0;
        FILE *out;
        char *buffer, tmpfile[PATH_MAX];
+       bool success = false;
        int fd, result, bytes, needflush = 0, needout = 0;
 
        if (!s->opened)
@@ -546,13 +547,20 @@ vcedit_write (vcedit_state *s)
                s->eosin = !bytes && feof (s->in);
        } while (!s->eosin);
 
-       fclose (out);
+       success = true;
+
+cleanup:
        fclose (s->in);
 
-       unlink (s->filename);
-       rename (tmpfile, s->filename);
+       if (!success) {
+               unlink (tmpfile);
+               fclose (out);
+       } else {
+               fclose (out);
+               unlink (s->filename);
+               rename (tmpfile, s->filename);
+       }
 
-cleanup:
        ogg_stream_clear (&streamout);
 
     /* We don't ogg_packet_clear() this, because the memory was