From 256dd5198cf83b0297b7326970e2d00798975deb Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 10 Feb 2015 12:48:14 -0800 Subject: [PATCH] Free allocated memory Closes #146 --- build/curve25519.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/build/curve25519.js b/build/curve25519.js index 5bb938fc..d5aebceb 100644 --- a/build/curve25519.js +++ b/build/curve25519.js @@ -56,6 +56,10 @@ var res = new Uint8Array(32); _readBytes(publicKey_ptr, 32, res); + Module._free(publicKey_ptr); + Module._free(privateKey_ptr); + Module._free(basepoint_ptr); + return Promise.resolve({ pubKey: res.buffer, privKey: privKey }); }, sharedSecret: function(pubKey, privKey) { @@ -76,6 +80,11 @@ var res = new Uint8Array(32); _readBytes(sharedKey_ptr, 32, res); + + Module._free(sharedKey_ptr); + Module._free(privateKey_ptr); + Module._free(basepoint_ptr); + return Promise.resolve(res.buffer); }, sign: function(privKey, message) { @@ -95,6 +104,11 @@ var res = new Uint8Array(64); _readBytes(signature_ptr, 64, res); + + Module._free(signature_ptr); + Module._free(privateKey_ptr); + Module._free(message_ptr); + return Promise.resolve(res.buffer); }, verify: function(pubKey, message, sig) { @@ -112,6 +126,10 @@ message_ptr, message.byteLength); + Module._free(publicKey_ptr); + Module._free(signature_ptr); + Module._free(message_ptr); + return new Promise(function(resolve, reject) { if (res !== 0) { reject(new Error("Invalid signature"));