简体   繁体   English

本地时间()中的malloc()段错误?

[英]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. mallocfree内部崩溃的情况,在99.999%的情况下是其他地方较早的堆损坏的结果。

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. 这可能导致随后的崩溃在堆损坏的例子malloc :呼吁free在非分配的内存,呼吁free一些指针两次,溢或下溢堆分配的缓冲区,等等等等。

The fastest way to find such bugs are: valgrind (if available on your platform), or AddressSanitizer (implemented in recent versions of Clang and GCC). 查找此类错误的最快方法是: valgrind (如果在您的平台上可用)或AddressSanitizer (在Clang和GCC的最新版本中实现)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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