localtime() 中的 malloc() 段错误?

编程入门 行业动态 更新时间:2024-10-19 04:22:54
本文介绍了localtime() 中的 malloc() 段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是 ny 堆栈

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.

有什么想法吗?

推荐答案

有什么想法吗?

malloc 或 free 中的任何崩溃在 99.999% 的情况下都是其他地方早期堆损坏的结果.

Any crash inside malloc or free is in 99.999% of cases the result of earlier heap corruption elsewhere.

可能导致 malloc 后续崩溃的堆损坏示例:在未分配的内存上调用 free,在某些内存上调用 free两次指针,上溢或下溢堆分配的缓冲区,等等.

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.

查找此类错误的最快方法是:valgrind(如果在您的平台上可用)或 AddressSanitizer(在 Clang 和 GCC 的最新版本中实现).

The fastest way to find such bugs are: valgrind (if available on your platform), or AddressSanitizer (implemented in recent versions of Clang and GCC).

更多推荐

localtime() 中的 malloc() 段错误?

本文发布于:2023-10-09 05:56:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1474894.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   localtime   malloc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!