edits
[iotcloud.git] / version2 / src / C / Slot.cc
index f4247e44d36941c7a2c247980c4a353cd93c6084..4a6f268d016ac2d4418b0bb100274b7449c8a0ea 100644 (file)
@@ -46,6 +46,15 @@ Slot::Slot(Table *_table, int64_t _seqnum, int64_t _machineid, int64_t _localSeq
        localSequenceNumber(_localSequenceNumber) {
 }
 
+Slot::~Slot() {
+       if (hmac != NULL)
+               delete hmac;
+       delete prevhmac;
+       for(uint i=0; i< entries->size(); i++)
+               delete entries->get(i);
+       delete entries;
+}
+
 Entry *Slot::addEntry(Entry *e) {
        e = e->getCopy(this);
        entries->add(e);
@@ -84,7 +93,8 @@ Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac) {
        bb->get(prevhmac);
        if (!realmac->equals(hmac))
                throw new Error("Server Error: Invalid HMAC!  Potential Attack!");
-
+       delete realmac;
+       
        int64_t seqnum = bb->getLong();
        int64_t machineid = bb->getLong();
        int numentries = bb->getInt();
@@ -93,10 +103,15 @@ Slot *Slot_decode(Table *table, Array<char> *array, Mac *mac) {
        for (int i = 0; i < numentries; i++) {
                slot->addShallowEntry(Entry_decode(slot, bb));
        }
-
+       bb->releaseArray();
+       delete bb;
        return slot;
 }
 
+char Slot::getType() {
+       return TypeSlot;
+}
+
 Array<char> *Slot::encode(Mac *mac) {
        Array<char> *array = new Array<char>(SLOT_SIZE);
        ByteBuffer *bb = ByteBuffer_wrap(array);
@@ -116,6 +131,8 @@ Array<char> *Slot::encode(Mac *mac) {
        hmac = realmac;
        bb->position(0);
        bb->put(realmac);
+       bb->releaseArray();
+       delete bb;
        return array;
 }