C++ 中止:内核转储
我的结构如下所示:C++ 中止:内核转储,c++,C++,我的结构如下所示: struct reply_t { reply_t (unsigned int _xid){ xid = _xid; cb_present = false; buf = NULL; sz = 0; } unsigned int xid; bool cb_present; // whether th
struct reply_t {
reply_t (unsigned int _xid){
xid = _xid;
cb_present = false;
buf = NULL;
sz = 0;
}
unsigned int xid;
bool cb_present; // whether the reply buffer is valid
char *buf; // the reply buffer
int sz; // the size of reply buffer
};
std::map<unsigned int, std::list<reply_t> > reply_window_;
我有一个std::map,如下所示:
struct reply_t {
reply_t (unsigned int _xid){
xid = _xid;
cb_present = false;
buf = NULL;
sz = 0;
}
unsigned int xid;
bool cb_present; // whether the reply buffer is valid
char *buf; // the reply buffer
int sz; // the size of reply buffer
};
std::map<unsigned int, std::list<reply_t> > reply_window_;
有人能告诉我这里发生了什么吗?buff是如何分配内存的?更好的是,为什么你把C风格的内存分配混合到C++中?这看起来是一个更好的工作,<代码> Buf<代码>:<代码> STD::String 或
free()
只能用于释放从malloc
函数系列中获得的指针。您发布的代码没有显示buf
的分配。我知道buf的大小是“sz”。我只使用malloc函数将内存分配给buf。还是不走运!!对该代码的多次调用将在同一指针上调用free。释放buf后,请尝试将其设置为NULL,以阻止这种情况发生。