Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 中止:内核转储_C++ - Fatal编程技术网

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 或 STD::vector < /C> >,使用<代码>:ST::当然,除非僵尸状态对您的设计至关重要。
free()
只能用于释放从
malloc
函数系列中获得的指针。您发布的代码没有显示
buf
的分配。我知道buf的大小是“sz”。我只使用malloc函数将内存分配给buf。还是不走运!!对该代码的多次调用将在同一指针上调用free。释放buf后,请尝试将其设置为NULL,以阻止这种情况发生。