问题
Here's ny stack
malloc() at 0xb7dfd333
strdup() at 0xb7e01866
tzset_internal() at 0xb7e2ef68
__tz_convert() at 0xb7e2f26a
localtime() at 0xb7e2d901
Send_Trace() at my_trace.c:265 0x8053373
and here's the offending code ..
void Send_Trace(const char const *Trace_Text, ...)
{
time_t time_now = time(NULL);
tm = *localtime(&time_now);
It is generally working fine, but occassionally throws the seg fault shown above.
Any ideas?
回答1:
Any ideas?
Any crash inside malloc or free is in 99.999% of cases the result of earlier heap corruption elsewhere.
Examples of heap corruption which could lead to subsequent crash in malloc: calling free on a non-allocated memory, calling free on some pointer twice, overflowing or underflowing a heap-allocated buffer, etc. etc.
The fastest way to find such bugs are: valgrind (if available on your platform), or AddressSanitizer (implemented in recent versions of Clang and GCC).
来源:https://stackoverflow.com/questions/39507994/malloc-seg-fault-in-localtime