Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/AbstractList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ template <typename T> class AbstractList {
/// Create a final Value from the given Value
#define createFinalValue(value, finalValue, T) \
finalValue = (T *)malloc(sizeof(T)); \
memcpy(finalValue, &(value), sizeof(T));
memcpy(finalValue, &value, sizeof(T));

/**
* Class representing an abstract entry in the list.
Expand All @@ -65,6 +65,11 @@ template <typename T> class AbstractList {
*/
explicit AbstractEntry(T *value) : value(value) {}

/*!
* @brief Destructor of an AbstractEntry Object.
*/
~AbstractEntry() { value = nullptr; }

/*!
* @brief Free the memory of the value to prevent memory leaks.
*/
Expand Down
12 changes: 10 additions & 2 deletions src/DoubleLinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
*/
explicit Entry(T *value) : AbstractList<T>::AbstractEntry(value) {}

/*!
* @brief Destructor of an Entry Object.
*/
~Entry() {
next = nullptr;
prev = nullptr;
}

/*!
* @brief Get the next entry of the list.
*
Expand Down Expand Up @@ -109,9 +117,9 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
if (this->isMutable()) {
return (T *)current->getValue();
} else {
T val = *current->getValue();
T *val = current->getValue();
T *finalValue;
createFinalValue(val, finalValue, T);
createFinalValue(*val, finalValue, T);
return finalValue;
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/SingleLinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
*/
explicit Entry(T *value) : AbstractList<T>::AbstractEntry(value) {}

/*!
* @brief Destructor of an Entry Object.
*/
~Entry() { next = nullptr; }

/*!
* @brief Get the next entry of the list.
*
Expand Down Expand Up @@ -87,9 +92,9 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
if (this->isMutable()) {
return (T *)current->getValue();
} else {
T val = *current->getValue();
T *val = current->getValue();
T *finalValue;
createFinalValue(val, finalValue, T);
createFinalValue(*val, finalValue, T);
return finalValue;
}
}
Expand Down