*** glibc检测到*** free():无效的指针:
*** glibc detected *** free(): invalid pointer:
我对上述glibc误差的原因感到完全困惑。我必须缺少一些明显的东西,但是每当以下程序(由4个文件组成)退出时,它会出现:
tanksim.h:
#ifndef TANKSIM_WDECAY_TANKSIM_H_
#define TANKSIM_WDECAY_TANKSIM_H_
#include <cstdlib>
#include <iostream>
#include "Parser.h"
int main();
#endif
tanksim.cpp:
#include "TankSim.h"
using std::cout;
using std::endl;
int main()
{
const Settings gGlobals = ParseConfig();
return(0);
}
parser.h:
#ifndef TANKSIM_WDECAY_PARSER_H_
#define TANKSIM_WDECAY_PARSER_H_
#include <cstdlib>
#include <vector>
#include <fstream>
#include <sstream>
#include <iostream>
struct Settings {
double speedlight;
double refractiveindex;
double absorptionchance;
double pmtradius;
double photspermetre;
double tankradius;
double tankheight;
long unsigned int randomseed;
double scatterangle;
std::vector<double> entrypoint;
std::vector<double> entrydrn;
};
Settings ParseConfig();
#endif
parser.cpp:
#include "Parser.h"
using std::string;
using std::vector;
using std::cout;
using std::endl;
Settings ParseConfig()
{
Settings settings;
std::ifstream configfile("settings.dat");
string line;
while(getline(configfile,line)){
//Comments start with %
if(line.find("%") != string::npos){
cout << "Comment: " << line << endl;
continue;
}
//Read in variable name.
std::stringstream ss;
ss << line;
string varname;
ss >> varname;
string value = line.substr(varname.length()+1);
cout << varname << "-" << value << endl;
}
}
由于我没有明确调用任何删除操作员,所以我不知道为什么会发生错误。
很可能是缺少的返回语句。
然后,在您的主要方法中,Settings
本地对象永远不会初始化。然后,它的范围结束了,其中矢量的驱动器被称为,他们认为自己有指针(因为它们是在记忆中使用垃圾的初始化),并在其指针上调用删除。
添加-Wall
启用所有警告将来会告诉您有关此信息的信息。
相关文章:
- 如何实现容纳整数和无效指针的双向链表?
- 在基数排序中,我得到 munmap_chunk():无效指针和中止(核心转储).为什么?
- 应用地址清理器后,免费无效指针消失
- C++ 在具有数组成员的类上无效指针/双精度释放
- 不断得到分段错误和free()无效指针
- 使用无效指针初始化指针声明符的行为是否未定义?
- 结构作为参数的函数产生错误:free():无效指针:0x00007efd47b
- 无效指针、隔离标识符等
- c++ 无效指针从空闲列表中取消排队
- C++ munmap_chunk(): 无效指针:
- 为什么我的简单C++程序使用队列和 fstream 错误到无效指针
- 无效指针和非初始化的指针之间的差异
- 如何用无效指针初始化unique_ptr的向量
- 地址清理器在静态强制转换无效指针时报告错误
- MS4:Free(Free()无效指针0xB74E74E0 ***
- ***检测到的GLIBC *** MS2:free():无效指针:0xB7526FF4 ***
- 无效指针功能的输出
- 有人能告诉我这是如何在main()中实现的吗?(关于无效指针的问题)
- C++11使用智能指针,但得到无效指针
- 无效指针的相关性