aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test/nif_SUITE_data
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2011-10-28 12:13:07 +0200
committerSverker Eriksson <[email protected]>2011-10-31 16:10:53 +0100
commitbf2b0f7fbea5cbe0e90021a930fa71570f4b837b (patch)
tree03423666baee7b8e78e547d9edc3ae7fda921d0e /erts/emulator/test/nif_SUITE_data
parentc8053ef7b602e8c47b6fa8919b9bbff996d3a81b (diff)
downloadotp-bf2b0f7fbea5cbe0e90021a930fa71570f4b837b.tar.gz
otp-bf2b0f7fbea5cbe0e90021a930fa71570f4b837b.tar.bz2
otp-bf2b0f7fbea5cbe0e90021a930fa71570f4b837b.zip
erts: Fix memory leak of enif_inspect_* on independent environment
Affects enif_inspect_iolist_as_binary() on iolists and enif_inspect_binary() on byte-unaligned binaries. Also need to allocate inspection buffers in ERTS_ALC_T_NIF for process independent environments, as we don't know when and where the environment will be freed.
Diffstat (limited to 'erts/emulator/test/nif_SUITE_data')
-rw-r--r--erts/emulator/test/nif_SUITE_data/nif_SUITE.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
index 35f54d62c5..7d7903af25 100644
--- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
+++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
@@ -1431,6 +1431,26 @@ static ERL_NIF_TERM reverse_list(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar
return rev_list;
}
+static ERL_NIF_TERM otp_9668_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+ /* Inspect in process independent env */
+ ErlNifEnv* myenv = enif_alloc_env();
+ ERL_NIF_TERM mycopy = enif_make_copy(myenv, argv[0]);
+ ErlNifBinary obin, cbin;
+
+ if ((enif_inspect_binary(env, argv[0], &obin)
+ && enif_inspect_binary(myenv, mycopy, &cbin))
+ ||
+ (enif_inspect_iolist_as_binary(env, argv[0], &obin)
+ && enif_inspect_iolist_as_binary(myenv, mycopy, &cbin)))
+ {
+ assert(obin.size == cbin.size);
+ assert(memcmp(obin.data, cbin.data, obin.size) == 0);
+ }
+ enif_free_env(myenv);
+ return atom_ok;
+}
+
static ErlNifFunc nif_funcs[] =
{
{"lib_version", 0, lib_version},
@@ -1478,7 +1498,8 @@ static ErlNifFunc nif_funcs[] =
{"send_term", 2, send_term},
{"reverse_list",1, reverse_list},
{"echo_int", 1, echo_int},
- {"type_sizes", 0, type_sizes}
+ {"type_sizes", 0, type_sizes},
+ {"otp_9668_nif", 1, otp_9668_nif}
};
ERL_NIF_INIT(nif_SUITE,nif_funcs,load,reload,upgrade,unload)