aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2011-09-29 18:01:34 +0200
committerLukas Larsson <[email protected]>2011-09-29 18:01:34 +0200
commitbeaa58d5724c4ae45a716accdeee58961a27e1d9 (patch)
tree31b3018e850b6cf3ea26cbeaab67208f1a79dcb9 /erts/emulator
parent1be1c1cb15068aed40a30210c8be34f36e38ed66 (diff)
parentb75eb2e04df5ccce6f9e62c67fbf8d8a9ac8f425 (diff)
downloadotp-beaa58d5724c4ae45a716accdeee58961a27e1d9.tar.gz
otp-beaa58d5724c4ae45a716accdeee58961a27e1d9.tar.bz2
otp-beaa58d5724c4ae45a716accdeee58961a27e1d9.zip
Merge branch 'sverker/stub-module-code-leakage' into dev
* sverker/stub-module-code-leakage: Prevent valgrind warning for erts_alloc_permanent_cache_aligned [erts] Fix memory leak in erts_make_stub_module (hipe loading)
Diffstat (limited to 'erts/emulator')
-rw-r--r--erts/emulator/beam/beam_load.c37
-rw-r--r--erts/emulator/beam/erl_alloc.c25
-rw-r--r--erts/emulator/beam/erl_alloc.h16
3 files changed, 44 insertions, 34 deletions
diff --git a/erts/emulator/beam/beam_load.c b/erts/emulator/beam/beam_load.c
index eb10ae59a8..fceb352cf3 100644
--- a/erts/emulator/beam/beam_load.c
+++ b/erts/emulator/beam/beam_load.c
@@ -635,6 +635,25 @@ bin_load(Process *c_p, ErtsProcLocks c_p_locks,
}
/*
+ * Initialize code area.
+ */
+ state.code_buffer_size = erts_next_heap_size(2048 + state.num_functions, 0);
+ state.code = (BeamInstr *) erts_alloc(ERTS_ALC_T_CODE,
+ sizeof(BeamInstr) * state.code_buffer_size);
+
+ state.code[MI_NUM_FUNCTIONS] = state.num_functions;
+ state.ci = MI_FUNCTIONS + state.num_functions + 1;
+
+ state.code[MI_ATTR_PTR] = 0;
+ state.code[MI_ATTR_SIZE] = 0;
+ state.code[MI_ATTR_SIZE_ON_HEAP] = 0;
+ state.code[MI_COMPILE_PTR] = 0;
+ state.code[MI_COMPILE_SIZE] = 0;
+ state.code[MI_COMPILE_SIZE_ON_HEAP] = 0;
+ state.code[MI_NUM_BREAKPOINTS] = 0;
+
+
+ /*
* Read the atom table.
*/
@@ -1363,24 +1382,6 @@ read_code_header(LoaderState* stp)
#endif
}
- /*
- * Initialize code area.
- */
- stp->code_buffer_size = erts_next_heap_size(2048 + stp->num_functions, 0);
- stp->code = (BeamInstr *) erts_alloc(ERTS_ALC_T_CODE,
- sizeof(BeamInstr) * stp->code_buffer_size);
-
- stp->code[MI_NUM_FUNCTIONS] = stp->num_functions;
- stp->ci = MI_FUNCTIONS + stp->num_functions + 1;
-
- stp->code[MI_ATTR_PTR] = 0;
- stp->code[MI_ATTR_SIZE] = 0;
- stp->code[MI_ATTR_SIZE_ON_HEAP] = 0;
- stp->code[MI_COMPILE_PTR] = 0;
- stp->code[MI_COMPILE_SIZE] = 0;
- stp->code[MI_COMPILE_SIZE_ON_HEAP] = 0;
- stp->code[MI_NUM_BREAKPOINTS] = 0;
-
stp->new_bs_put_strings = 0;
stp->catches = 0;
return 1;
diff --git a/erts/emulator/beam/erl_alloc.c b/erts/emulator/beam/erl_alloc.c
index bbc8a445a7..9af80dd7a9 100644
--- a/erts/emulator/beam/erl_alloc.c
+++ b/erts/emulator/beam/erl_alloc.c
@@ -2960,6 +2960,29 @@ erts_allocator_options(void *proc)
return res;
}
+void *erts_alloc_permanent_cache_aligned(ErtsAlcType_t type, Uint size)
+{
+ UWord v = (UWord) erts_alloc(type, size + (ERTS_CACHE_LINE_SIZE-1));
+
+#ifdef VALGRIND
+ { /* Avoid Leak_PossiblyLost */
+ static UWord vg_root_set[10];
+ static unsigned ix = 0;
+ if (ix >= sizeof(vg_root_set) / sizeof(*vg_root_set)) {
+ erl_exit(ERTS_ABORT_EXIT, "Too many erts_alloc_permanent_cache_aligned's\n");
+ }
+ vg_root_set[ix++] = v; /* not thread safe */
+ }
+#endif
+
+ if (v & ERTS_CACHE_LINE_MASK) {
+ v = (v & ~ERTS_CACHE_LINE_MASK) + ERTS_CACHE_LINE_SIZE;
+ }
+ ASSERT((v & ERTS_CACHE_LINE_MASK) == 0);
+ return (void*)v;
+}
+
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Deprecated functions *
* *
@@ -3583,6 +3606,4 @@ install_debug_functions(void)
return FENCE_SZ;
}
-
-
#endif /* #ifdef DEBUG */
diff --git a/erts/emulator/beam/erl_alloc.h b/erts/emulator/beam/erl_alloc.h
index c35a60da22..80cb82c393 100644
--- a/erts/emulator/beam/erl_alloc.h
+++ b/erts/emulator/beam/erl_alloc.h
@@ -180,11 +180,11 @@ void *erts_realloc(ErtsAlcType_t type, void *ptr, Uint size);
void erts_free(ErtsAlcType_t type, void *ptr);
void *erts_alloc_fnf(ErtsAlcType_t type, Uint size);
void *erts_realloc_fnf(ErtsAlcType_t type, void *ptr, Uint size);
-void *erts_alloc_permanent_cache_aligned(ErtsAlcType_t type, Uint size);
-
#endif /* #if !ERTS_ALC_DO_INLINE */
+void *erts_alloc_permanent_cache_aligned(ErtsAlcType_t type, Uint size);
+
#ifndef ERTS_CACHE_LINE_SIZE
/* Assume a cache line size of 64 bytes */
# define ERTS_CACHE_LINE_SIZE ((UWord) 64)
@@ -250,18 +250,6 @@ void *erts_realloc_fnf(ErtsAlcType_t type, void *ptr, Uint size)
size);
}
-ERTS_ALC_INLINE
-void *erts_alloc_permanent_cache_aligned(ErtsAlcType_t type, Uint size)
-{
- UWord v = (UWord) erts_alloc(type, size + (ERTS_CACHE_LINE_SIZE-1));
-
- if (v & ERTS_CACHE_LINE_MASK) {
- v = (v & ~ERTS_CACHE_LINE_MASK) + ERTS_CACHE_LINE_SIZE;
- }
- ASSERT((v & ERTS_CACHE_LINE_MASK) == 0);
- return (void*)v;
-}
-
#endif /* #if ERTS_ALC_DO_INLINE || defined(ERTS_ALC_INTERNAL__) */
typedef void (*erts_alloc_verify_func_t)(Allctr_t *);