summaryrefslogtreecommitdiff
path: root/libs/evoral/src/SMF.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-01-05 15:50:30 -0500
committerDavid Robillard <d@drobilla.net>2015-01-05 15:50:30 -0500
commitb56905b9a79c48548f8100ab77c28533a5820ab3 (patch)
tree4fff39525eb1efb0d186138bb11cb3997c9953ba /libs/evoral/src/SMF.cpp
parenta488f7a22119c901a7d02292a1d24b3a1bb577f9 (diff)
Fix MIDI file descriptor leaks.
Pretty sure this is the cause of MIDI data going missing on save for optimized builds. Introduced in 294b99aabf3eb96323a3159b7a5e1b4bfc1ff04a.
Diffstat (limited to 'libs/evoral/src/SMF.cpp')
-rw-r--r--libs/evoral/src/SMF.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/libs/evoral/src/SMF.cpp b/libs/evoral/src/SMF.cpp
index 218e2851ff..42c5369b76 100644
--- a/libs/evoral/src/SMF.cpp
+++ b/libs/evoral/src/SMF.cpp
@@ -78,17 +78,18 @@ SMF::seek_to_track(int track)
bool
SMF::test(const std::string& path)
{
- FILE* f = fopen (path.c_str(), "r");
+ FILE* f = fopen(path.c_str(), "r");
if (f == 0) {
return false;
}
- smf_t* test_smf;
- if ((test_smf = smf_load (f)) == NULL) {
- return false;
- }
- smf_delete (test_smf);
- return true;
+ smf_t* test_smf = smf_load(f);
+ fclose(f);
+
+ const bool success = (test_smf != NULL);
+ smf_delete(test_smf);
+
+ return success;
}
/** Attempt to open the SMF file for reading and/or writing.
@@ -109,16 +110,14 @@ SMF::open(const std::string& path, int track) THROW_FILE_ERROR
_file_path = path;
- FILE* f = fopen (_file_path.c_str(), "r");
+ FILE* f = fopen(_file_path.c_str(), "r");
if (f == 0) {
return -1;
- }
-
- if ((_smf = smf_load (f)) == 0) {
+ } else if ((_smf = smf_load(f)) == 0) {
+ fclose(f);
return -1;
- }
-
- if ((_smf_track = smf_get_track_by_number(_smf, track)) == 0) {
+ } else if ((_smf_track = smf_get_track_by_number(_smf, track)) == 0) {
+ fclose(f);
return -2;
}
@@ -131,6 +130,7 @@ SMF::open(const std::string& path, int track) THROW_FILE_ERROR
_empty = false;
}
+ fclose(f);
return 0;
}
@@ -186,8 +186,10 @@ SMF::create(const std::string& path, int track, uint16_t ppqn) THROW_FILE_ERROR
}
if (smf_save (_smf, f)) {
+ fclose (f);
return -1;
}
+ fclose (f);
}
_empty = true;
@@ -403,8 +405,11 @@ SMF::end_write() THROW_FILE_ERROR
}
if (smf_save(_smf, f) != 0) {
+ fclose(f);
throw FileError (_file_path);
}
+
+ fclose(f);
}
double