edits
[iotcloud.git] / version2 / src / C / SlotBuffer.cc
index 2ce4a66147b20a2091126ed83cf4d0dc38faeadd..af6b031ba36b911e6e24a359875ef32c3a0fc649 100644 (file)
@@ -14,6 +14,13 @@ SlotBuffer::SlotBuffer() :
 }
 
 SlotBuffer::~SlotBuffer() {
+       uint index = tail;
+       while (index != head) {
+               delete array->get(index);
+               index++;
+               if (index == array->length())
+                       index = 0;
+       }
        delete array;
 }
 
@@ -36,7 +43,7 @@ void SlotBuffer::resize(int newsize) {
        int index = tail;
        for (int i = 0; i < currsize; i++) {
                newarray->set(i, array->get(index));
-               if (((uint32_t)++index) == array->length())
+               if (((uint32_t)++ index) == array->length())
                        index = 0;
        }
        array = newarray;
@@ -51,6 +58,7 @@ void SlotBuffer::incrementHead() {
 }
 
 void SlotBuffer::incrementTail() {
+       delete array->get(tail);
        tail++;
        if (((uint32_t)tail) >= array->length())
                tail = 0;
@@ -60,6 +68,13 @@ void SlotBuffer::putSlot(Slot *s) {
        int64_t checkNum = (getNewestSeqNum() + 1);
 
        if (checkNum != s->getSequenceNumber()) {
+               uint index = tail;
+               while (index != head) {
+                       delete array->get(index);
+                       index++;
+                       if (index == array->length())
+                               index = 0;
+               }
                oldestseqn = s->getSequenceNumber();
                tail = 0;
                head = 1;