这个是出问题的函数:
void SetModuleIdentities(std::vector[u]& identities)
{
std::vector testVec;
for (uint32_t const& identity : identities)
{
printf("enter... testVec.size=%ld %ld\n", testVec.size(), testVec.capacity());
ModuleConfig newModule;
newModule.identity = identity;
testVec.push_back(newModule);
printf("leave... testVec.size=%ld %ld\n", testVec.size(), testVec.capacity());
}
}
这是 ModuleConfig 的定义:
struct ModuleConfig
{
ModuleConfig()
{
printf("ModuleConfig::constructor\n");
}
~ModuleConfig()
{
printf("ModuleConfig::destructor\n");
}
uint32_t identity;
std::string pdoMapName;
uint32_t pdoMapInOffset;
uint32_t pdoMapOutOffset;
};
执行的输出如下:
enter... testVec.size=0 0
ModuleConfig::constructor
leave... testVec.size=3353953467947191204 1
ModuleConfig::destructor
# 然后就崩溃了
这是部分调用栈信息(来源 sighandler ):
15:03:36 ecpanda exit with 11
crash time:Thu May 18 15:03:36 2023
./base/lib-linux/bin/ecpanda-generic(_Z10sigHandleriP9siginfo_tPv+0x96) [0x56266aff3e9a]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14420) [0x7f528d9d7420]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x20) [0x7f528d50b6f0]
./base/lib-linux/bin/ecpanda-generic(_ZN12ModuleConfigD1Ev+0x2c) [0x56266b0075e6]
./base/lib-linux/bin/ecpanda-generic(_ZN15SlaveFileConfig19SetModuleIdentitiesERSt6vectorIjSaIjEE+0x136) [0x56266b017138]
./base/lib-linux/bin/ecpanda-generic(_Z23ESI_SetModuleIdentitiesiRSt6vectorIjSaIjEE+0x42) [0x56266b01692c]
我就 push_back 了一下,怎么就把 vector 干崩了呢?
vector, uint32_t, lib-linux, printf