fix: leaks: deletes first contact befort replace it

This commit is contained in:
Camille Chauvet 2023-05-22 17:34:19 +00:00
parent 7bc9220a7a
commit 908691c5da

View File

@ -2,6 +2,7 @@
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
@ -20,6 +21,7 @@ void PhoneBook::add_contact(Contact *new_contact)
{
size_t i;
std::cout << std::endl << this->len << std::endl;
if (this->len < 8)
{
this->contacts[this->len] = new_contact;
@ -27,7 +29,8 @@ void PhoneBook::add_contact(Contact *new_contact)
}
else
{
for (i = this->len; i != 0; i--) {
delete this->contacts[0];
for (i = this->len - 1; i > 0; i--) {
this->contacts[i] = this->contacts[i - 1];
}
this->contacts[0] = new_contact;