shithub: aubio

Download patch

ref: 65a4fb4d95e51cf33ee9f90a5dfb20f5addd9f7c
parent: ba9e3a87995fb80a32257076d8f3228368d7acf4
author: Paul Brossier <piem@piem.org>
date: Tue Jan 8 13:51:16 EST 2019

[sink_wavwrite] call fflush in open

This ensures the file header was actually written correctly, and fails
otherwise, for instance when the target disk-system is full.

--- a/src/io/sink_wavwrite.c
+++ b/src/io/sink_wavwrite.c
@@ -211,9 +211,11 @@
   written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
 
   // fwrite(*, *, 1, s->fid) was called 13 times, check success
-  if (written != 13) {
-    AUBIO_STRERR("sink_wavwrite: writing header to %s failed, expected %d"
-        " write but got only %d (%s)\n", s->path, 13, written, errorstr);
+  if (written != 13 || fflush(s->fid)) {
+    AUBIO_STRERR("sink_wavwrite: writing header to %s failed"
+        " (wrote %d/%d, %s)\n", s->path, written, 13, errorstr);
+    fclose(s->fid);
+    s->fid = NULL;
     return AUBIO_FAIL;
   }