日期:2014-05-16  浏览次数:20679 次

LINUX 下使用 MAP,执行时报错,求助,
typedef unsigned long       DWORD;
typedef struct _tagStructPlatformService
{
DWORD dwId;
DWORD dwFunctionId;
DWORD dwCount;
}StructPlatformService;
typedef map<DWORD, StructPlatformService *> CMapPlatformService;

StructPlatformService *pStructPlatformService = new StructPlatformService;
pStructPlatformService->dwId=atoi(pData[0]);
pStructPlatformService->dwFunctionId=atoi(pData[1]);
pStructPlatformService->dwCount =atoi(pData[2]);
DWORD nKey=pStructPlatformService->dwId;
CMapPlatformService::iterator itr=m_pStructDatabaseMapManage->mapPlatformService.find(nKey);
在执行到find(nKey)程序就崩溃了,
bt内容如下:
(gdb) bt
#0  0x08058166 in std::less<unsigned long>::operator() (this=0x8122ad0, __x=@0xb8000010, __y=@0xb6e16ba8)
    at /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_function.h:230
#1  0x08059025 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, StructPlatformService*>, std::_Select1st<std::pair<unsigned long const, StructPlatformService*> >, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, StructPlatformService*> > >::_M_lower_bound (this=0x8122ad0, __x=0xb8000000, __y=0x8122ad4, __k=@0xb6e16ba8)
    at /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_tree.h:986
#2  0x08057f10 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, StructPlatformService*>, std::_Select1st<std::pair<unsigned long const, StructPlatformService*> >, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, StructPlatformService*> > >::find (this=0x8122ad0, __k=@0xb6e16ba8)
    at /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_tree.h:1421
#3  0x0805705a in std::map<unsigned long, StructPlatformService*, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, StructPlatformService*> > >::find (this=0x8122ad0, __x=@0xb6e16ba8)
    at /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_map.h:659

程序在写完后一直没有问题,突然有一天执行,就崩溃了。
还有在未初初化的情况下执行:
m_StructDatabaseMapManage.mapPlatformService.clear();
也会崩溃。
研究了好久都没有解决。向大大们求助了。
------解决方案--------------------
代码没看出什么问题,如果运行了一段时间后才出错的话,也可能是其它地方引起的,比如在同一个栈内的数组越界,破坏了mapPlatformService的内存。

还有在未初初化的情况下执行:
m_StructDatabaseMapManage.mapPlatformService.clear();
也会崩溃。

建议另建立一个小的测试工程,看看是否也会崩溃,然后再比较正式项目的写法。
------解决方案--------------------
最重要的堆栈信息是最后几个,你给了最上面的几个,木用。
m_pStructDatabaseMapManage为空否?
mapPlatformService合法否?