google / google/tcmalloc

Segfault when LD_PRELOADed tcmalloc.so

Open
#107 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5.3k
Forks
570
Avg merge
23h 43m
Merged PRs (30d)
172

Description

When I LD_PRELOADed the tcmalloc.so and ran the binary, I got the segfault. Then, I ran the binary with gdb, in that case, I got the following error message:

```
tcmalloc/tcmalloc.cc:1868] size check failed 16 8 1
tcmalloc/tcmalloc.cc:2241] CorrectSize(p, size, DefaultAlignPolicy()) @ 0x155554b226c8 0x155554b8576a 0x5555559666b3
Aborted (core dumped)
```

Below is the source code, from where this error message is printed.

```
// Checks that an asserted object size for is valid.
template
bool CorrectSize(void* ptr, size_t size, AlignPolicy align) {
// size == 0 means we got no hint from sized delete, so we certainly don't
// have an incorrect one.
if (size == 0) return true;
if (ptr == nullptr) return true;
uint32_t cl = 0;
// Round-up passed in size to how much tcmalloc allocates for that size.
if (Static::guardedpage_allocator().PointerIsMine(ptr)) {
size = Static::guardedpage_allocator().GetRequestedSize(ptr);
} else if (Static::sizemap().GetSizeClass(CppPolicy().AlignAs(align.align()),
size, &cl)) {
size = Static::sizemap().class_to_size(cl);
} else {
size = BytesToLengthCeil(size).in_bytes();
}
size_t actual = GetSize(ptr);
if (ABSL_PREDICT_TRUE(actual == size)) return true;
// We might have had a cold size class, which then sampled, so actual > size.
// Let's check that.
//
// TODO(b/124707070): When we grow a sampled allocation in this way,
// recompute the true size at allocation time. This allows size-feedback from
// operator new to benefit from the bytes we are allocating.
if (actual > size && IsSampledMemory(ptr)) {
if (Static::sizemap().GetSizeClass(
CppPolicy().AlignAs(align.align()).AccessAsCold(), size, &cl)) {
size = Static::sizemap().class_to_size(cl);
if (actual == size) {
return true;
}
}
}
**Log(kLog, __FILE__, __LINE__, "size check failed", actual, size, cl);**
return false;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.