Node FFI wrapper function fails when used synchronously, but works asynchronously
<p>I'm trying to wrap a Rust library (that exposes a C API) with Node FFI. I have the following code wrapping two functions. One is a "constructor" that returns a pointer. The other takes a pointer and returns C string.</p>

<pre><code>var libcomm = ffi.Library('lib/c_api/target/debug/libcomm', {
  'comm_address_for_content': ['pointer', ['string']],
  'comm_address_to_str': ['string', ['pointer']]
});
</code></pre>

<p>When I use the asynchronous invocation of <code>comm_address_to_str</code> the response is correct. However, when I try to call the function using the synchronous style, it returns garbage, or very very rarely, the correct result. The following nodeunit test exercises the scenario:</p>

<pre><code>const comm = require("../").libcomm;

exports.testAddressForContent = function (test) {
  const ptr = comm.comm_address_for_content('test');

  const result = comm.comm_address_to_str(ptr);
  test.equal(result, 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'); // always fails
  console.log('sync', result); // random garbage

  comm.comm_address_to_str.async(ptr, function(err, result) {
    test.equal(result, 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'); // always passes
    console.log('async', result); // 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'
    test.done();
  });
}
</code></pre>

<p>I can't figure out what causes this, but I need to be able to use the sync invocation style. The C API of the Rust library I am wrapping is <a href="https://github.com/zacstewart/comm/blob/master/c_api/src/comm.rs" rel="nofollow">here</a>.</p>