免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4004 | 回复: 8
打印 上一主题 下一主题

请教malloc:Error accessing memory address 0x0: 无效的变元 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-10-16 15:31 |只看该作者 |倒序浏览
20可用积分

  1. string timestr("");//时间文字
  2. if(time_flag==1)
  3. {
  4.   struct tm *now;
  5.   char str_t[40];
  6.   now   = localtime(&timer);  
  7.   sprintf(str_t,"%02d:%02d:%02d:",now->tm_hour,now->tm_min,now->tm_sec);
  8.   timestr=str_t;    // 此处core dump
  9. ……
复制代码
gdb -c core
Detected 64-bit corefile.
Invoking /opt/langtools/bin/gdb64.
HP gdb 3.3 for PA-RISC 2.0 (wide), HP-UX 11.00.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 3.3 (based on GDB) is covered by the
GNU General Public License. Type "show copying" to see the conditions to
change it and/or distribute copies. Type "show warranty" for warranty/support.

Reading symbols from CallComparator...done.
Core was generated by `CallComparator'.
Program terminated with signal 11, Segmentation fault.

warning: The shared libraries were not privately mapped; setting a
breakpoint in a shared library will not work until you rerun the program.

wher
warning: section .data not found in /arrayindb/app/oracle/app/oracle9/product/9.2.0/lib/libwtc9.sl
e#0  0x800003ffbef82558 in .stub+0x460 () from /usr/lib/pa20_64//libc.2
(gdb) where
#0  0x800003ffbef82558 in .stub+0x460 () from /usr/lib/pa20_64//libc.2
#1  0x800003ffbef7fef8 in .stub+0x680 () from /usr/lib/pa20_64//libc.2
#2  0x800003ffbef8566c in malloc+0x1c4 () from /usr/lib/pa20_64//libc.2
Error accessing memory address 0x0: 无效的变元.
(gdb)

论坛徽章:
0
2 [报告]
发表于 2007-10-16 15:39 |只看该作者
timestr是常量?
string类型和char []类型是一回事吗?

论坛徽章:
0
3 [报告]
发表于 2007-10-16 17:51 |只看该作者

回复 #2 cugb_cat 的帖子

又出错了,详细信息是:
(gdb)
0x800003ffbefe418c in time+0x2c () from /usr/lib/pa20_64//libc.2
(gdb)
Single stepping until exit from function time,
which has no line number information.
CLogManager::WriteLog (this=0x800000010004bfd0, str={<class std::allocator<char>> = {<No data fields>},
      static npos = 18446744073709551615, static __nullref = {__ref_hdr_ = {__mutex_ = {<struct __rw::__rw_mutex_base> = {
              _C_mutex = {<No data fields>}}, <No data fields>}, __refs_ = 1, __capacity_ = 0, __nchars_ = 0},
        __eos_char_ = 0 '\000'}, _C_data = 0x8000000100295578 "正在遍历本方(主叫)数据源... (遍历数10001/总数3761033)"},
    warnlevel=0, time_flag=1, throwex=true) at ../public/LogManager.cpp:153
153                     now   = localtime(&timer);      
(gdb) p now
$19 = (struct tm *) 0x800003ffbfff1d70
(gdb) p *now
$20 = {tm_sec = 0, tm_min = 0, tm_hour = -2147482625, tm_mday = -1089454912, tm_mon = -2147482625, tm_year = -1091123745,
  tm_wday = 0, tm_yday = 310536, tm_isdst = -1}
(gdb) n
154                     sprintf(str_t,"%02d:%02d:%02d:",now->tm_hour,now->tm_min,now->tm_sec);
(gdb) p *now
$21 = {tm_sec = 59, tm_min = 46, tm_hour = 17, tm_mday = 16, tm_mon = 9, tm_year = 107, tm_wday = 2, tm_yday = 288, tm_isdst = 0}
(gdb) n
155                     timestr=str_t;
(gdb) p str_t
$22 = "17:46:59:\000\000\001\000\004絓b

论坛徽章:
0
4 [报告]
发表于 2007-10-16 19:28 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
5 [报告]
发表于 2007-10-16 20:48 |只看该作者
timestr=str_t;    // 此处core dump


试试:
timestr.assign(str_t)

论坛徽章:
0
6 [报告]
发表于 2007-10-16 21:05 |只看该作者
我的经验,在此之前已经有memory corruption. 建议用debug allocator 试试

论坛徽章:
0
7 [报告]
发表于 2007-10-16 21:51 |只看该作者
原帖由 Alligator27 于 2007-10-16 21:05 发表
我的经验,在此之前已经有memory corruption. 建议用debug allocator 试试


是。我的经验也是,应该错误在此之前。
但是我跟踪了多次,都在此处core dump。

请教debug allocator是什么操作?

论坛徽章:
0
8 [报告]
发表于 2007-10-16 22:33 |只看该作者
我的意思是诊断memory error的工具,HP gdb有这功能。

论坛徽章:
0
9 [报告]
发表于 2007-10-17 10:29 |只看该作者
有点怪,暂时不知道原因,看你调试的结果了。

另外,localtime 是非线程安全的,如果你是在多线程环境下跑,试试换成 localtime_r 再看看呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP