luigi1111 / xmr.llcoins.net

XMR Tools Site Files
MIT License
67 stars 26 forks source link

Crypto.js does not implement the _free function: function _free() { } #13

Open will-yjn opened 2 years ago

will-yjn commented 2 years ago

https://github.com/luigi1111/xmr.llcoins.net/blob/master/site/js/crypto.js

In the crypto.js file, the _free function is not implemented. Right?

It seems this causes a bug:

function sc_reduce32(hex) {
    var input = hextobin(hex);
    if (input?.length !== 32) {
        throw "Invalid input length";
    }
    // Module._malloc() return the address of the alloced memory - the pointer
    var mem = Module._malloc(32);
    Module.HEAPU8.set(input, mem);
    Module.ccall('sc_reduce32', 'void', ['number'], [mem]);
    var output = Module.HEAPU8.subarray(mem, mem + 32);
    Module._free(mem);
    return bintohex(output);
};

In the above snippet of code, since the memory is not actually freed, so if you run this function, say 10k times, then the crypto.js will throw an error:

Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 16777216, (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.