projects
/
ruby-vorbistagger.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Close and remove the temporary file if vcedit_write() fails.
[ruby-vorbistagger.git]
/
ext
/
vcedit.c
diff --git
a/ext/vcedit.c
b/ext/vcedit.c
index cf63e7487217c7a36fcb479590328488928c7c63..38ecb9f9d384818c84df6a0e96b85274fdd34767 100644
(file)
--- 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];
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)
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);
s->eosin = !bytes && feof (s->in);
} while (!s->eosin);
- fclose (out);
+ success = true;
+
+cleanup:
fclose (s->in);
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
ogg_stream_clear (&streamout);
/* We don't ogg_packet_clear() this, because the memory was