diff --git a/recording-daemon/db.c b/recording-daemon/db.c index 61e1d8c96..49a3890f8 100644 --- a/recording-daemon/db.c +++ b/recording-daemon/db.c @@ -385,14 +385,15 @@ void db_close_stream(output_t *op) { return; } fseek(f, 0, SEEK_END); - stream.len = ftell(f); - if (stream.len < 0) { + long pos = ftell(f); + if (pos < 0) { ilog(LOG_ERR, "Failed to get file position: %s", strerror(errno)); fclose(f); if ((output_storage & OUTPUT_STORAGE_FILE)) goto file; return; } + stream.len = pos; fseek(f, 0, SEEK_SET); stream.s = malloc(stream.len); if (stream.s) {