memory-safety improved

This commit is contained in:
A-lex-Ra
2023-12-18 18:02:17 +06:00
parent 779a8101fa
commit 6830205bcc
3 changed files with 59 additions and 32 deletions
+10 -4
View File
@@ -176,6 +176,7 @@ bool load_wav_file_header(std::ifstream& file,
return true;
}
// after that user must free returned memory by himself!
char* load_wav(const std::string& filename,
std::uint8_t& channels,
std::int32_t& sampleRate,
@@ -192,8 +193,13 @@ char* load_wav(const std::string& filename,
}
char* data = new char[size];
in.read(data, size);
return data;
try {
in.read(data, size);
return data;
}
catch (const std::exception&) {
delete[] data;
std::cerr << "ERROR: Could not load wav data of \"" << filename << "\"" << std::endl;
return nullptr;
}
}