diff options
author | Sverker Eriksson <[email protected]> | 2014-09-04 16:59:41 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2014-09-04 16:59:41 +0200 |
commit | 267cf6cd5ba5e4392718c3c6f7f6467ac01ea2b0 (patch) | |
tree | 97f285eeac2f25d9563d4082c15020be9b90f1e2 /erts/emulator/test/nif_SUITE_data | |
parent | e036643fbd5c5cba7f652734966570fee7ca99b3 (diff) | |
parent | b182aa2cfab793e566c92183c361e78f4d6f84cb (diff) | |
download | otp-267cf6cd5ba5e4392718c3c6f7f6467ac01ea2b0.tar.gz otp-267cf6cd5ba5e4392718c3c6f7f6467ac01ea2b0.tar.bz2 otp-267cf6cd5ba5e4392718c3c6f7f6467ac01ea2b0.zip |
Merge branch 'sverk/nif-inspect-copy-bug/OTP-9828' into maint
* sverk/nif-inspect-copy-bug/OTP-9828:
erts: Fix bug with enif_make_copy reallocating writable binary
Conflicts:
erts/emulator/test/nif_SUITE.erl
Diffstat (limited to 'erts/emulator/test/nif_SUITE_data')
-rw-r--r-- | erts/emulator/test/nif_SUITE_data/nif_SUITE.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c index ad9d5d9254..ff5fb8c5af 100644 --- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c +++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c @@ -1473,6 +1473,26 @@ static ERL_NIF_TERM otp_9668_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar return atom_ok; } +static ERL_NIF_TERM otp_9828_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + /* copy a writable binary could reallocate it due to "emasculation" + and thereby render a previous inspection invalid. + */ + ErlNifBinary bin1; + ErlNifEnv* myenv; + + if (!enif_inspect_binary(env, argv[0], &bin1)) { + return enif_make_badarg(env); + } + + myenv = enif_alloc_env(); + enif_make_copy(myenv, argv[0]); + enif_free_env(myenv); + + return memcmp(bin1.data, "I'm alive!", 10)==0 ? atom_ok : atom_false; +} + + static ERL_NIF_TERM consume_timeslice_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { int percent; @@ -1772,6 +1792,7 @@ static ErlNifFunc nif_funcs[] = {"echo_int", 1, echo_int}, {"type_sizes", 0, type_sizes}, {"otp_9668_nif", 1, otp_9668_nif}, + {"otp_9828_nif", 1, otp_9828_nif}, {"consume_timeslice_nif", 2, consume_timeslice_nif}, {"call_nif_schedule", 2, call_nif_schedule}, #ifdef ERL_NIF_DIRTY_SCHEDULER_SUPPORT |