From 42092cfa6986555710a470db10b8bcd1f714dd16 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Fri, 18 Aug 2006 15:45:19 +0200 Subject: [PATCH] Close and remove the temporary file if vcedit_write() fails. --- ext/vcedit.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ext/vcedit.c b/ext/vcedit.c index cf63e74..38ecb9f 100644 --- a/ext/vcedit.c +++ b/ext/vcedit.c @@ -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 -- 2.30.2