Skip to content

Commit 12860f7

Browse files
committed
h_malloc_info: reduce scope of unsealed metadata
This is needed since fprintf can end up calling malloc which would result in sealing the metadata again.
1 parent 0989875 commit 12860f7

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

h_malloc.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,21 +2049,22 @@ EXPORT int h_malloc_info(int options, FILE *fp) {
20492049

20502050
#if CONFIG_STATS
20512051
if (likely(is_init())) {
2052-
thread_unseal_metadata();
2053-
20542052
for (unsigned arena = 0; arena < N_ARENA; arena++) {
20552053
fprintf(fp, "<heap nr=\"%u\">", arena);
20562054

20572055
for (unsigned class = 0; class < N_SIZE_CLASSES; class++) {
2058-
struct size_class *c = &ro.size_class_metadata[arena][class];
2056+
thread_unseal_metadata();
20592057

2058+
struct size_class *c = &ro.size_class_metadata[arena][class];
20602059
mutex_lock(&c->lock);
20612060
u64 nmalloc = c->nmalloc;
20622061
u64 ndalloc = c->ndalloc;
20632062
size_t slab_allocated = c->slab_allocated;
20642063
size_t allocated = c->allocated;
20652064
mutex_unlock(&c->lock);
20662065

2066+
thread_seal_metadata();
2067+
20672068
if (nmalloc || ndalloc || slab_allocated || allocated) {
20682069
fprintf(fp, "<bin nr=\"%u\" size=\"%" PRIu32 "\">"
20692070
"<nmalloc>%" PRIu64 "</nmalloc>"
@@ -2078,16 +2079,18 @@ EXPORT int h_malloc_info(int options, FILE *fp) {
20782079
fputs("</heap>", fp);
20792080
}
20802081

2082+
thread_unseal_metadata();
2083+
20812084
struct region_allocator *ra = ro.region_allocator;
20822085
mutex_lock(&ra->lock);
20832086
size_t region_allocated = ra->allocated;
20842087
mutex_unlock(&ra->lock);
20852088

2089+
thread_seal_metadata();
2090+
20862091
fprintf(fp, "<heap nr=\"%u\">"
20872092
"<allocated_large>%zu</allocated_large>"
20882093
"</heap>", N_ARENA, region_allocated);
2089-
2090-
thread_seal_metadata();
20912094
}
20922095
#endif
20932096

0 commit comments

Comments
 (0)