「🔨」 fix: fixed leak when throwing
This commit is contained in:
@ -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;
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||
# Updated: 2025/05/30 13:24:23 by adjoly ### ########.fr #
|
||||
# Updated: 2025/06/30 10:51:07 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -22,7 +22,7 @@ SRCS = $(shell find . -name '*.cpp')
|
||||
|
||||
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||
|
||||
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
|
||||
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP -g
|
||||
|
||||
RED = \033[0;31m
|
||||
GREEN = \033[0;32m
|
||||
|
@ -6,11 +6,12 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/21 10:34:50 by adjoly #+# #+# */
|
||||
/* Updated: 2025/06/03 11:31:50 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/06/30 10:52:15 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <BitcoinExchange.hpp>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
@ -23,9 +24,11 @@ int main(int ac, char **av) {
|
||||
btc = new BitcoinExchange(av[1]);
|
||||
btc->print();
|
||||
} catch (std::runtime_error &e) {
|
||||
btc = NULL;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
delete btc;
|
||||
if (btc != NULL)
|
||||
delete btc;
|
||||
} else {
|
||||
std::cout << "Error: could not open file." << std::endl;
|
||||
}
|
||||
|
Reference in New Issue
Block a user