diff options
author | Rickard Green <rickard@erlang.org> | 2019-11-06 13:03:36 +0100 |
---|---|---|
committer | Rickard Green <rickard@erlang.org> | 2019-11-06 13:03:36 +0100 |
commit | 42de74576b254a1a24fd050018150fd823451ba6 (patch) | |
tree | 45bb370607db9b27acf38732cbd9e8541202e5c7 /erts/emulator/beam/sys.h | |
parent | b10d87f13335077a7593724db59a1ed3ef4e4122 (diff) | |
parent | 843b70004bbd5845137fc35b3fe1da98edef1e8a (diff) | |
download | erlang-42de74576b254a1a24fd050018150fd823451ba6.tar.gz |
Merge branch 'sverker/dist-entry-refc-bug/ERL-1044/OTP-16224' into maint
* sverker/dist-entry-refc-bug/ERL-1044/OTP-16224:
erts: Fix bug causing leak of DistEntry
erts: Fix write-after-free bug for DistEntry
Diffstat (limited to 'erts/emulator/beam/sys.h')
-rw-r--r-- | erts/emulator/beam/sys.h | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/erts/emulator/beam/sys.h b/erts/emulator/beam/sys.h index c261c8e117..c534891f30 100644 --- a/erts/emulator/beam/sys.h +++ b/erts/emulator/beam/sys.h @@ -901,6 +901,9 @@ ERTS_GLB_INLINE void erts_refc_inc(erts_refc_t *refcp, erts_aint_t min_val); ERTS_GLB_INLINE erts_aint_t erts_refc_inc_unless(erts_refc_t *refcp, erts_aint_t unless_val, erts_aint_t min_val); +ERTS_GLB_INLINE void erts_refc_inc_if(erts_refc_t *refcp, + erts_aint_t if_val, + erts_aint_t min_val); ERTS_GLB_INLINE erts_aint_t erts_refc_inctest(erts_refc_t *refcp, erts_aint_t min_val); ERTS_GLB_INLINE void erts_refc_dec(erts_refc_t *refcp, erts_aint_t min_val); @@ -942,7 +945,7 @@ erts_refc_inc_unless(erts_refc_t *refcp, while (1) { erts_aint_t exp, new; #ifdef ERTS_REFC_DEBUG - if (val < 0) + if (val < min_val) erts_exit(ERTS_ABORT_EXIT, "erts_refc_inc_unless(): Bad refc found (refc=%ld < %ld)!\n", val, min_val); @@ -957,6 +960,27 @@ erts_refc_inc_unless(erts_refc_t *refcp, } } +ERTS_GLB_INLINE void +erts_refc_inc_if(erts_refc_t *refcp, + erts_aint_t if_val, + erts_aint_t min_val) +{ + erts_aint_t val = erts_atomic_read_nob((erts_atomic_t *) refcp); +#ifdef ERTS_REFC_DEBUG + if (val < min_val) + erts_exit(ERTS_ABORT_EXIT, + "erts_refc_inc_unless(): Bad refc found (refc=%ld < %ld)!\n", + val, min_val); +#endif + if (val == if_val) { + erts_atomic_cmpxchg_nob((erts_atomic_t *) refcp, val+1, val); + /* + * Ignore failure, as it means someone else took care of 'if_val'. + * Could be this function racing with itself. + */ + } +} + ERTS_GLB_INLINE erts_aint_t erts_refc_inctest(erts_refc_t *refcp, erts_aint_t min_val) { |