1
0

🔨」 fix: fixed leak when throwing

This commit is contained in:
2025-06-30 10:54:43 +02:00
parent da635ef59a
commit f8eaea321e
3 changed files with 17 additions and 8 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/21 10:39:45 by adjoly #+# #+# */
/* Updated: 2025/06/03 11:40:22 by adjoly ### ########.fr */
/* Updated: 2025/06/30 10:54:14 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -213,14 +213,18 @@ BitcoinExchange::BitcoinExchange(char *av) : _is(av), _filename(av) {
throw e;
}
if (!_is.is_open())
if (!_is.is_open()) {
delete _csv;
throw std::runtime_error("could not open file - " + _filename);
}
std::string buf;
std::getline(_is, buf);
if (buf != "date | value")
if (buf != "date | value") {
delete _csv;
throw std::runtime_error("file has not the good format - " + buf);
}
}
BitcoinExchange::BitcoinExchange(const BitcoinExchange &) {
@ -291,8 +295,10 @@ std::pair<Date, float> BitcoinExchange::_parseLine(void) {
void BitcoinExchange::_printPair(std::pair<Date, float> pair) {
auto map = _csv->getCsv();
auto it = std::find_if(map.begin(), map.end(), CompareDate(pair.first));
if (it == map.end())
if (it == map.end()) {
delete _csv;
throw std::out_of_range("out of range");
}
float i = it->second * pair.second;
std::cout << pair.first << " => " << pair.second << " = " << i << std::endl;