Update for 85088c5 288/head
authorsvost <ya.nowa@yandex.ru>
Sat, 12 Mar 2016 14:27:27 +0000 (17:27 +0300)
committersvost <ya.nowa@yandex.ru>
Sat, 12 Mar 2016 14:27:27 +0000 (17:27 +0300)
src/ecies.cpp
src/key.cpp

index 4d72bfd..3f8eaf7 100644 (file)
@@ -567,6 +567,7 @@ ies_ctx_t *create_context(EC_KEY *user_key)
     }
     catch (const std::bad_alloc& e) {
       printf("Error: %s in %s:%d\n", e.what(), __FILE__, __LINE__);
+// TODO: add checking to NULL where necessary
       return NULL;
     }
-}
+}
\ No newline at end of file
index 49868b8..2232324 100644 (file)
@@ -1202,7 +1202,7 @@ void CKey::EncryptData(const std::vector<unsigned char>& data, std::vector<unsig
 
     cryptogram = ecies_encrypt(ctx, (unsigned char*)&data[0], data.size(), error);
     if (cryptogram == NULL) {
-        free(ctx);
+        delete ctx;
         ctx = NULL;
         throw key_error(std::string("Error in encryption: %s") + error);
     }
@@ -1211,7 +1211,7 @@ void CKey::EncryptData(const std::vector<unsigned char>& data, std::vector<unsig
     unsigned char *key_data = cryptogram_key_data(cryptogram);
     memcpy(&encrypted[0], key_data, encrypted.size());
     cryptogram_free(cryptogram);
-    free(ctx);
+    delete ctx;
 }
 
 void CKey::DecryptData(const std::vector<unsigned char>& encrypted, std::vector<unsigned char>& data)
@@ -1234,7 +1234,7 @@ void CKey::DecryptData(const std::vector<unsigned char>& encrypted, std::vector<
 
     decrypted = ecies_decrypt(ctx, cryptogram, &length, error);
     cryptogram_free(cryptogram);
-    free(ctx);
+    delete ctx;
 
     if (decrypted == NULL) {
         throw key_error(std::string("Error in decryption: %s") + error);
@@ -1243,4 +1243,4 @@ void CKey::DecryptData(const std::vector<unsigned char>& encrypted, std::vector<
     data.resize(length);
     memcpy(&data[0], decrypted, length);
     free(decrypted);
-}
+}
\ No newline at end of file