Free allocated memory

Closes #146
This commit is contained in:
lilia 2015-02-10 12:48:14 -08:00
parent 9d592bf117
commit 256dd5198c

View file

@ -56,6 +56,10 @@
var res = new Uint8Array(32); var res = new Uint8Array(32);
_readBytes(publicKey_ptr, 32, res); _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 }); return Promise.resolve({ pubKey: res.buffer, privKey: privKey });
}, },
sharedSecret: function(pubKey, privKey) { sharedSecret: function(pubKey, privKey) {
@ -76,6 +80,11 @@
var res = new Uint8Array(32); var res = new Uint8Array(32);
_readBytes(sharedKey_ptr, 32, res); _readBytes(sharedKey_ptr, 32, res);
Module._free(sharedKey_ptr);
Module._free(privateKey_ptr);
Module._free(basepoint_ptr);
return Promise.resolve(res.buffer); return Promise.resolve(res.buffer);
}, },
sign: function(privKey, message) { sign: function(privKey, message) {
@ -95,6 +104,11 @@
var res = new Uint8Array(64); var res = new Uint8Array(64);
_readBytes(signature_ptr, 64, res); _readBytes(signature_ptr, 64, res);
Module._free(signature_ptr);
Module._free(privateKey_ptr);
Module._free(message_ptr);
return Promise.resolve(res.buffer); return Promise.resolve(res.buffer);
}, },
verify: function(pubKey, message, sig) { verify: function(pubKey, message, sig) {
@ -112,6 +126,10 @@
message_ptr, message_ptr,
message.byteLength); message.byteLength);
Module._free(publicKey_ptr);
Module._free(signature_ptr);
Module._free(message_ptr);
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
if (res !== 0) { if (res !== 0) {
reject(new Error("Invalid signature")); reject(new Error("Invalid signature"));