File tree Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ template <typename T> class AbstractList {
4848 // / Create a final Value from the given Value
4949#define createFinalValue (value, finalValue, T ) \
5050 finalValue = (T *)malloc(sizeof (T)); \
51- memcpy (finalValue, &( value) , sizeof (T));
51+ memcpy (finalValue, &value, sizeof (T));
5252
5353 /* *
5454 * Class representing an abstract entry in the list.
@@ -65,6 +65,11 @@ template <typename T> class AbstractList {
6565 */
6666 explicit AbstractEntry (T *value) : value(value) {}
6767
68+ /* !
69+ * @brief Destructor of an AbstractEntry Object.
70+ */
71+ ~AbstractEntry () { value = nullptr ; }
72+
6873 /* !
6974 * @brief Free the memory of the value to prevent memory leaks.
7075 */
Original file line number Diff line number Diff line change @@ -51,6 +51,14 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
5151 */
5252 explicit Entry (T *value) : AbstractList<T>::AbstractEntry(value) {}
5353
54+ /* !
55+ * @brief Destructor of an Entry Object.
56+ */
57+ ~Entry () {
58+ next = nullptr ;
59+ prev = nullptr ;
60+ }
61+
5462 /* !
5563 * @brief Get the next entry of the list.
5664 *
@@ -109,9 +117,9 @@ template <typename T> class DoubleLinkedList : public AbstractList<T> {
109117 if (this ->isMutable ()) {
110118 return (T *)current->getValue ();
111119 } else {
112- T val = * current->getValue ();
120+ T * val = current->getValue ();
113121 T *finalValue;
114- createFinalValue (val, finalValue, T);
122+ createFinalValue (* val, finalValue, T);
115123 return finalValue;
116124 }
117125 }
Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
5050 */
5151 explicit Entry (T *value) : AbstractList<T>::AbstractEntry(value) {}
5252
53+ /* !
54+ * @brief Destructor of an Entry Object.
55+ */
56+ ~Entry () { next = nullptr ; }
57+
5358 /* !
5459 * @brief Get the next entry of the list.
5560 *
@@ -87,9 +92,9 @@ template <typename T> class SingleLinkedList : public AbstractList<T> {
8792 if (this ->isMutable ()) {
8893 return (T *)current->getValue ();
8994 } else {
90- T val = * current->getValue ();
95+ T * val = current->getValue ();
9196 T *finalValue;
92- createFinalValue (val, finalValue, T);
97+ createFinalValue (* val, finalValue, T);
9398 return finalValue;
9499 }
95100 }
You can’t perform that action at this time.
0 commit comments