summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSverker Eriksson <sverker@erlang.org>2021-03-10 13:05:58 +0100
committerSverker Eriksson <sverker@erlang.org>2021-03-10 13:05:58 +0100
commit9f93bcad4e7231fd58a9f5ef52deaa8c81901dc3 (patch)
treee088f74357cd9cdfb52ad80e9af083089e1c1450
parent2264a12043a56271ba2ecdd24ca2c7bc31921ad7 (diff)
parent465cca7df433f1b3d9e310ab7ca827bb9a5c73ab (diff)
downloaderlang-9f93bcad4e7231fd58a9f5ef52deaa8c81901dc3.tar.gz
Merge branch 'sverker/erts/tracer-opt-leaks/OTP-17265' into maint
PR-4596
-rw-r--r--erts/emulator/beam/erl_bif_trace.c15
-rw-r--r--erts/emulator/test/trace_SUITE.erl12
2 files changed, 23 insertions, 4 deletions
diff --git a/erts/emulator/beam/erl_bif_trace.c b/erts/emulator/beam/erl_bif_trace.c
index 36cad53ce4..b688e82e70 100644
--- a/erts/emulator/beam/erl_bif_trace.c
+++ b/erts/emulator/beam/erl_bif_trace.c
@@ -465,19 +465,25 @@ erts_trace_flags(Eterm List,
cpu_timestamp = !0;
#endif
} else if (is_tuple(item)) {
+ ERTS_TRACER_CLEAR(&tracer);
tracer = erts_term_to_tracer(am_tracer, item);
if (tracer == THE_NON_VALUE)
goto error;
} else goto error;
list = CDR(list_val(list));
}
- if (is_not_nil(list)) goto error;
+ if (is_not_nil(list)) {
+ goto error;
+ }
- if (pMask && mask) *pMask = mask;
- if (pTracer && !ERTS_TRACER_IS_NIL(tracer)) *pTracer = tracer;
- if (pCpuTimestamp && cpu_timestamp) *pCpuTimestamp = cpu_timestamp;
+ if (mask) *pMask = mask;
+ if (!ERTS_TRACER_IS_NIL(tracer)) *pTracer = tracer;
+ if (cpu_timestamp) *pCpuTimestamp = cpu_timestamp;
return !0;
+
error:
+ if (tracer != THE_NON_VALUE)
+ ERTS_TRACER_CLEAR(&tracer);
return 0;
}
@@ -541,6 +547,7 @@ Eterm erts_internal_trace_3(BIF_ALIST_3)
}
if (!erts_try_seize_code_write_permission(BIF_P)) {
+ ERTS_TRACER_CLEAR(&tracer);
ERTS_BIF_YIELD3(&bif_trap_export[BIF_erts_internal_trace_3],
BIF_P, BIF_ARG_1, BIF_ARG_2, BIF_ARG_3);
}
diff --git a/erts/emulator/test/trace_SUITE.erl b/erts/emulator/test/trace_SUITE.erl
index 025f5282fb..951502cb61 100644
--- a/erts/emulator/test/trace_SUITE.erl
+++ b/erts/emulator/test/trace_SUITE.erl
@@ -1684,6 +1684,18 @@ bad_flag(Config) when is_list(Config) ->
{'EXIT', {badarg, _}} = (catch erlang:trace(new,
true,
[not_a_valid_flag])),
+
+ %% Leaks of {tracer,_} in OTP 23.2
+ Pid = spawn(fun() -> receive die -> ok end end),
+ 1 = erlang:trace(Pid, true, [{tracer, self()},
+ {tracer, self()}]),
+ Pid ! die,
+ {'EXIT', {badarg, _}} =
+ (catch erlang:trace(new, true, [{tracer, self()}
+ | improper])),
+ {'EXIT', {badarg, _}} =
+ (catch erlang:trace(new, true, [{tracer, self()},
+ not_a_valid_flag])),
ok.
%% Test erlang:trace_delivered/1