[erlang-questions] Issue with using enif_binary_to_term

Vincent Siliakus zambal@REDACTED
Mon May 14 22:57:18 CEST 2018


Hi all,

I'm writing a NIF library and can't wrap my head around why the following
code makes the erlang runtime hang when called from a shell:

  static ERL_NIF_TERM test(ErlNifEnv* env, int argc, const ERL_NIF_TERM
argv[]) {
    ErlNifBinary bin;

    ERL_NIF_TERM list = enif_make_list(env, 0);
    ERL_NIF_TERM in_term = enif_make_uint(env, 42);
    ERL_NIF_TERM out_term1, out_term2, out_term3;

    enif_term_to_binary(env, in_term, &bin);

    enif_binary_to_term(env, bin.data, bin.size, &out_term1, 0);
    list = enif_make_list_cell(env, out_term1, list);

    enif_binary_to_term(env, bin.data, bin.size, &out_term2, 0);
    list = enif_make_list_cell(env, out_term2, list);

    enif_binary_to_term(env, bin.data, bin.size, &out_term3, 0);
    list = enif_make_list_cell(env, out_term3, list);

    return list;
  }

The multiple calls to enif_binary_to_term somehow seem to corrupt memory in
the calling environment, so I'm probably using it incorrectly. Could some
kind soul point me to the error? I'm running this code on OTP20 / erts-9.2.

Thanks in advance,
Vincent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180514/14fb8083/attachment.htm>


More information about the erlang-questions mailing list