fix: fixing memory & fd leaks
This commit is contained in:
parent
5720cbd635
commit
1b83e7a47a
4 changed files with 13 additions and 9 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/17 14:20:06 by rparodi #+# #+# */
|
/* 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(std::string const name, int execute, int sign);
|
||||||
Form(Form const ©);
|
Form(Form const ©);
|
||||||
Form& operator=(Form const &assign);
|
Form& operator=(Form const &assign);
|
||||||
~Form();
|
virtual ~Form();
|
||||||
class GradeTooHighException : public std::exception {
|
class GradeTooHighException : public std::exception {
|
||||||
virtual const char *what() const throw() {
|
virtual const char *what() const throw() {
|
||||||
return ("Error:\n> Grade is too high (have to be lower than 1)");
|
return ("Error:\n> Grade is too high (have to be lower than 1)");
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/19 19:43:56 by rparodi #+# #+# */
|
/* 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() {
|
Intern::Intern() {
|
||||||
std::cout << "[Intern] default constructor" << std::endl;
|
std::cout << "[Intern] default constructor" << std::endl;
|
||||||
|
_ptr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Intern::Intern(Intern const & copy) {
|
Intern::Intern(Intern const & copy) {
|
||||||
|
|
@ -31,6 +32,7 @@ Intern& Intern::operator= (Intern const & assign) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Intern::~Intern() {
|
Intern::~Intern() {
|
||||||
|
delete this->_ptr;
|
||||||
std::cout << "[Intern] destructor" << std::endl;
|
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;
|
std::cout << "Intern creates " << type << std::endl;
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
return new ShrubberyCreationForm(target);
|
_ptr = new ShrubberyCreationForm(target);
|
||||||
case 1:
|
case 1:
|
||||||
return new RobotomyRequestForm(target);
|
_ptr = new RobotomyRequestForm(target);
|
||||||
case 2:
|
case 2:
|
||||||
return new PresidentialPardonForm(target);
|
_ptr = new PresidentialPardonForm(target);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Intern could not create " << type << std::endl;
|
std::cout << "Intern could not create " << type << std::endl;
|
||||||
return NULL;
|
return _ptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/19 19:43:54 by rparodi #+# #+# */
|
/* 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"
|
#include "ShrubberyCreationForm.hpp"
|
||||||
|
|
||||||
class Intern {
|
class Intern {
|
||||||
|
private:
|
||||||
|
Form *_ptr;
|
||||||
public:
|
public:
|
||||||
Intern();
|
Intern();
|
||||||
Intern(Intern const & copy);
|
Intern(Intern const & copy);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/16 14:47:26 by rparodi #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue