fix: fixing memory & fd leaks

This commit is contained in:
Raphael 2025-03-19 20:30:50 +01:00
parent 5720cbd635
commit 1b83e7a47a
4 changed files with 13 additions and 9 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/17 14:20:06 by rparodi #+# #+# */
/* Updated: 2025/03/19 19:57:45 by rparodi ### ########.fr */
/* Updated: 2025/03/19 20:29:51 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,7 +26,7 @@ class Form {
Form(std::string const name, int execute, int sign);
Form(Form const &copy);
Form& operator=(Form const &assign);
~Form();
virtual ~Form();
class GradeTooHighException : public std::exception {
virtual const char *what() const throw() {
return ("Error:\n> Grade is too high (have to be lower than 1)");

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 19:43:56 by rparodi #+# #+# */
/* Updated: 2025/03/19 20:18:23 by rparodi ### ########.fr */
/* Updated: 2025/03/19 20:29:04 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,7 @@
Intern::Intern() {
std::cout << "[Intern] default constructor" << std::endl;
_ptr = NULL;
}
Intern::Intern(Intern const & copy) {
@ -31,6 +32,7 @@ Intern& Intern::operator= (Intern const & assign) {
}
Intern::~Intern() {
delete this->_ptr;
std::cout << "[Intern] destructor" << std::endl;
}
@ -41,16 +43,16 @@ Form* Intern::makeForm(std::string type, std::string target) {
std::cout << "Intern creates " << type << std::endl;
switch (i) {
case 0:
return new ShrubberyCreationForm(target);
_ptr = new ShrubberyCreationForm(target);
case 1:
return new RobotomyRequestForm(target);
_ptr = new RobotomyRequestForm(target);
case 2:
return new PresidentialPardonForm(target);
_ptr = new PresidentialPardonForm(target);
default:
break;
}
}
}
std::cout << "Intern could not create " << type << std::endl;
return NULL;
return _ptr;
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 19:43:54 by rparodi #+# #+# */
/* Updated: 2025/03/19 20:17:55 by rparodi ### ########.fr */
/* Updated: 2025/03/19 20:29:37 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,6 +20,8 @@
#include "ShrubberyCreationForm.hpp"
class Intern {
private:
Form *_ptr;
public:
Intern();
Intern(Intern const & copy);

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/16 14:47:26 by rparodi #+# #+# */
/* Updated: 2025/03/19 20:21:34 by rparodi ### ########.fr */
/* Updated: 2025/03/19 20:26:46 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */