uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

commit 24e3f432004425f5e8be6f3e4f10ceaff9355205
parent 82c4af18fa54a2ddabe4c15591d2347d786faff6
Author: Christos Margiolis <christos@margiolis.net>
Date:   Mon,  4 May 2020 21:14:57 +0300

fixed some memory leaks

Diffstat:
Massignment-2.2-classes/classes.cpp | 4+++-
Massignment-2.3-operoverloading/bin/operoverloading | 0
Massignment-2.3-operoverloading/obj/student.o | 0
Massignment-2.3-operoverloading/src/student.cpp | 4+++-
4 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/assignment-2.2-classes/classes.cpp b/assignment-2.2-classes/classes.cpp @@ -96,6 +96,7 @@ float *Student::get_grades() const void Student::set_AM(const char *AM) { + if (this->AM != nullptr) delete[] this->AM; this->AM = convert_AM(AM); } @@ -129,10 +130,11 @@ char *Student::convert_AM(const char *AM) float *Student::convert_PSG(const float *grades) { - if (psubj > 0) + if (psubj > 0 && grades != nullptr) { float *tmp = new float[psubj]; memcpy(tmp, grades, sizeof(float) * psubj); + if (this->grades != nullptr) delete[] this->grades; return tmp; } else return nullptr; diff --git a/assignment-2.3-operoverloading/bin/operoverloading b/assignment-2.3-operoverloading/bin/operoverloading Binary files differ. diff --git a/assignment-2.3-operoverloading/obj/student.o b/assignment-2.3-operoverloading/obj/student.o Binary files differ. diff --git a/assignment-2.3-operoverloading/src/student.cpp b/assignment-2.3-operoverloading/src/student.cpp @@ -146,6 +146,7 @@ unsigned int Student::get_num_submitted_subjects() const void Student::set_AM(const char *AM) { + if (this->AM != nullptr) delete[] this->AM; this->AM = convert_AM(AM); } @@ -193,10 +194,11 @@ char *Student::convert_AM(const char *AM) float *Student::convert_PSG(const float *grades) { - if (psubj > 0) + if (psubj > 0 && grades != nullptr) { float *tmp = new float[psubj]; memcpy(tmp, grades, sizeof(float) * psubj); + if (this->grades != nullptr) delete[] this->grades; return tmp; } else return nullptr;