crash caused by static variable

本文介绍了一段C++代码中出现的内存泄漏问题及其调试过程。通过对gdb回溯信息的解析,展示了如何定位到具体的问题所在,即一个组件创建映射表在析构过程中未能正确释放资源导致的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

the core :

#0  0x00007f00795ec600 in ?? ()   
(gdb) bt
#0  0x00007f00795ec600 in ?? ()   
#1  0x00007f007a5bc300 in ~function (this=0x7f007a7ec2e0, __x=0xcdc430) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/tr1/functional:1010
#2  ~pair (this=0x7f007a7ec2e0, __x=0xcdc430) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_pair.h:69
#3  destroy (this=0x7f007a7ec2e0, __x=0xcdc430) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:107
#4  destroy_node (this=0x7f007a7ec2e0, __x=0xcdc430) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_tree.h:391
#5  std::_Rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >,std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::tr1::function<m
odel_serving::IComponent* ()()> >,std::_Select1st<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::tr1::function<model_serving::IComponent* ()()> > >,std
::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >,std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::tr1::func
tion<model_serving::IComponent* ()()> > > >::_M_erase(std::_Rb_tree_node<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::tr1::function<model_serving::IC
omponent* ()()> > > *) (this=0x7f007a7ec2e0, __x=0xcdc430) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_tree.h:1266
#6  0x00007f007a5b7827 in ~_Rb_tree () at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_tree.h:578
#7  ~map () at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_map.h:93
#8  __tcf_10 () at build/release64/src/service/component_builder.cpp:11
#9  0x0000003d468337de in __cxa_finalize () from /lib64/libc.so.6
#10 0x00007f007a5b3746 in __do_global_dtors_aux () from /home/admin/myworks/asc_search_engine/trunk/model_serving_framework/model_serving/build/release64/lib/libmodel_serving.so
#11 0x0000000000000000 in ?? ()   
(gdb) f 8
#8  __tcf_10 () at build/release64/src/service/component_builder.cpp:11
11      static model_serving::ModelServingCompoentCreatorMapType staticComponentCreatorMap;
(gdb) p staticComponentCreatorMap 
$1 = std::map with 1 elementsTraceback (most recent call last):
  File "/usr/share/gdb/python/libstdcxx/v6/printers.py", line 286, in children
    keytype = self.val.type.template_argument(0).const()
RuntimeError: syntax error, near `)()>,std::less<std::basic_string<char'

component.h

#define REGISTER_MODEL_SERVING_COMPONENT(className) \
IComponent* Create##className() \
{ \
    return new className; \
} \
class RegisterModelServingComponent##className \
{ \
public: \
    RegisterModelServingComponent##className() \
    { \
        GetStaticCompoentFactoryFuncMap()[#className] = Create##className; \
    } \
}; \
static RegisterModelServingComponent##className gModelServing##className##Registor;

component_builder.cpp

#include "component.h"

ModelServingCompoentCreatorMapType& model_serving::GetStaticCompoentFactoryFuncMap()
{
    static model_serving::ModelServingCompoentCreatorMapType staticComponentCreatorMap;
    LOG_DEBUG(sLogger, ("GetComponentCreator", staticComponentCreatorMap.size()));
    return staticComponentCreatorMap;
}

test_component.cpp

//REGISTER_MODEL_SERVING_COMPONENT(EchoComponent); // why??
bool EchoComponent::Init(const KeyValueMap& confMap)
{
    LOG_CALL_DEBUG(sLogger);
    bool ret = false;
    MODEL_SERVER_LOAD_MODEL_SERVING_RESOURCE(confMap, ECHO_COMPONENT_CONF_DICT, mDict, ret);
    if (!ret)
    {
        LOG_WARNING(sLogger, ("LoadTestDictFail", ECHO_COMPONENT_CONF_DICT));
    }
    LOG_INFO(sLogger, ("EchoComponentInit","done"));
    return true;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值