As a fly-by fix, also let __cxa_demangle allocate its buffer alone,
since we are not allowed to pass a non-malloc'd buffer to it.
Details
- Reviewers
- None
- Group Reviewers
Restricted Project - Commits
- rG6089fd6c0b1c: [libc++abi] Refactor exception type demangling into a separate function
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libcxxabi/src/cxa_default_handlers.cpp | ||
---|---|---|
64–65 | This isn't code you're changing the meaning of, but this is broken. the buffer passed to __cxa_demangle must come from malloc. If ever a thrown type demangles to more than 1024 chars, people are going to be sad. |
libcxxabi/src/cxa_default_handlers.cpp | ||
---|---|---|
31–33 | if (auto *res = ...) return res; else return str; ? No need to pass in status -- we don't care why it can't demangle. |
Address review comment.
libcxxabi/src/cxa_default_handlers.cpp | ||
---|---|---|
64–65 | Thank you, that is an excellent observation. |
Address additional review comment.
libcxxabi/src/cxa_default_handlers.cpp | ||
---|---|---|
31–33 | I updated before seeing this comment, but yes, I agree, I can drop status as well. |
libcxxabi/src/cxa_default_handlers.cpp | ||
---|---|---|
64–65 | thanks, but you're now going to leak. you need something like: if (name != thrown_type->name()) std::free (name); somewhere. (I'm going to presume the optimizer can spot that's always false in the LIBCXXABI_NON_DEMANGLING_TERMINATE case). N.B. our demangler calls std::terminate in the event of memory exhaustion, rather than return null. I'm slowly trying to resolve that problem. |
Never leak!
libcxxabi/src/cxa_default_handlers.cpp | ||
---|---|---|
64–65 | I know we're leaking, but I was thinking it didn't matter because we were terminating anyways. This is actually what we were doing previously if the demangled name was more than 1024 characters long. __cxa_demangle would realloc and the resulting pointer would be leaked (assuming realloc doesn't try to free if the given buffer wasn't allocated with malloc). But hey, I can fix this easily with unique_ptr anyways. |
libcxxabi/src/cxa_default_handlers.cpp | ||
---|---|---|
64–65 | oh, good point. maybe a comment about leak don't care? |
libcxxabi/src/cxa_default_handlers.cpp | ||
---|---|---|
64–65 | There was a comment before above the demangle() function, but I removed it since I'm not leaking anymore (I use std::unique_ptr). Please LMK if that looks OK to you. |
libcxxabi/src/cxa_default_handlers.cpp | ||
---|---|---|
64–65 | This is fine. Sorry for not noticing that leaking doesn't matter and causing unnecessary rework. I hope the rework is not bloaty. |
Looks like @urnathan is OK with the patch now (thanks for the review!).
The AIX CI has been failing due to unrelated reasons, so ignoring that.
? No need to pass in status -- we don't care why it can't demangle.