From 908691c5daa1dd572362dfd25a3ba5193ee77e57 Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Mon, 22 May 2023 17:34:19 +0000 Subject: [PATCH] fix: leaks: deletes first contact befort replace it --- ex01/src/PhoneBook.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ex01/src/PhoneBook.cpp b/ex01/src/PhoneBook.cpp index 838b38c..76d04d8 100644 --- a/ex01/src/PhoneBook.cpp +++ b/ex01/src/PhoneBook.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -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;