简体   繁体   中英

malloc() seg fault in localtime()?

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM