Skip to content

Commit

Permalink
MINOR: activity/memprofile: always return "other" bin on NULL return …
Browse files Browse the repository at this point in the history
…address

It was found in a large "show profiling memory" output that a few entries
have a NULL return address, which causes confusion because this address
will be reused by the next new allocation caller, possibly resulting in
inconsistencies such as "free() ... pool=trash" which makes no sense. The
cause is in fact that the first caller had an entry->info pointing to the
trash pool from a p_alloc/p_free with a NULL return address, and the second
had a different type and reused that entry.

Let's make sure undecodable stacks causing an apparent NULL return address
all lead to the "other" bin.

While this is not exactly a bug, it would make sense to backport it to the
recent branches where the feature is used (probably at least as far as 2.8).

(cherry picked from commit 5091f90)
Signed-off-by: Christopher Faulet <[email protected]>
(cherry picked from commit 27ade1e)
Signed-off-by: Christopher Faulet <[email protected]>
(cherry picked from commit be90a54)
Signed-off-by: Christopher Faulet <[email protected]>
  • Loading branch information
wtarreau authored and capflam committed Oct 23, 2024
1 parent eb36c73 commit 772688e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ struct memprof_stats *memprof_get_bin(const void *ra, enum memprof_method meth)
const void *old;
unsigned int bin;

if (unlikely(!ra)) {
bin = MEMPROF_HASH_BUCKETS;
goto leave;
}
bin = ptr_hash(ra, MEMPROF_HASH_BITS);
for (; memprof_stats[bin].caller != ra; bin = (bin + 1) & (MEMPROF_HASH_BUCKETS - 1)) {
if (!--retries) {
Expand All @@ -193,6 +197,7 @@ struct memprof_stats *memprof_get_bin(const void *ra, enum memprof_method meth)
break;
}
}
leave:
return &memprof_stats[bin];
}

Expand Down

0 comments on commit 772688e

Please sign in to comment.