edits
[iotcloud.git] / version2 / src / C / CloudComm.cc
index c229259140501fa1384cb74eb1fa49824b58a5c9..8fe0ceeb256eddc802a076f3e6289798f0e5a90d 100644 (file)
@@ -46,7 +46,7 @@ void *threadWrapper(void *cloud) {
  * Constructor for actual use. Takes in the url and password.
  */
 CloudComm::CloudComm(Table *_table,  IoTString *_baseurl, IoTString *_password, int _listeningPort) :
-       baseurl(_baseurl),
+       baseurl(new IoTString(_baseurl)),
        key(NULL),
        mac(NULL),
        password(new IoTString(_password)),
@@ -74,6 +74,10 @@ CloudComm::~CloudComm() {
                delete random;
        if (baseurl)
                delete baseurl;
+       if (mac)
+               delete mac;
+       if (key)
+               delete key;
 }
 
 /**
@@ -135,6 +139,7 @@ IoTString *CloudComm::buildRequest(bool isput, int64_t sequencenumber, int64_t m
        if (maxentries != 0)
                sprintf(&buffer[offset], "&max=%" PRId64, maxentries);
        IoTString *urlstr = new IoTString(buffer);
+       free(buffer);
        return urlstr;
 }
 
@@ -225,6 +230,7 @@ WebConnection openURL(IoTString *url) {
        /* send the request */
        int total = strlen(message);
        loopWrite(sockfd, message, total);
+       free(message);
        return (WebConnection) {sockfd, -1};
 }
 
@@ -411,6 +417,7 @@ void CloudComm::setSalt() {
 
                timer->startTime();
                wc = openURL(urlstr);
+               delete urlstr;
                writeURLDataAndClose(&wc, saltTmp);
 
                int responsecode = getResponseCode(&wc);
@@ -554,11 +561,14 @@ Array<Slot *> *CloudComm::putSlot(Slot *slot, int max) {
 
                int64_t sequencenumber = slot->getSequenceNumber();
                Array<char> *slotBytes = slot->encode(mac);
-               Array<char> *chars = encryptSlotAndPrependIV(slotBytes, slot->getSlotCryptIV());
+               Array<char> * ivBytes = slot->getSlotCryptIV();
+               Array<char> *chars = encryptSlotAndPrependIV(slotBytes, ivBytes);
+               delete ivBytes;
                delete slotBytes;
                IoTString *url = buildRequest(true, sequencenumber, max);
                timer->startTime();
                wc = openURL(url);
+               delete url;
                writeURLDataAndClose(&wc, chars);
                delete chars;
                timer->endTime();
@@ -625,6 +635,7 @@ Array<Slot *> *CloudComm::getSlots(int64_t sequencenumber) {
                IoTString *url = buildRequest(false, sequencenumber, 0);
                timer->startTime();
                wc = openURL(url);
+               delete url;
                closeURLReq(&wc);
                timer->endTime();
        } catch (SocketTimeoutException *e) {