A malloc error in C++ - incorrect checksum for freed object
Hello everyone,
I wrote a program in C++ (called lab3_1) that compiled has no errors,
but when I run it returns in the Run Log this error that doesn't allow
it to terminate correctly:
lab3_1(318) malloc: *** error for object 0x1804600: incorrect checksum
for freed object - object was probably modified after being freed,
break at szone_error to debug
lab3_1(318) malloc: *** set a breakpoint in szone_error to debug
lab3_1(318) malloc: *** error for object 0x1802200: incorrect checksum
for freed object - object was probably modified after being freed,
break at szone_error to debug
lab3_1(318) malloc: *** set a breakpoint in szone_error to debug
The main of the program is:
#define SLEEP_LGTH 4
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "dataAnalysis.h"
#include "gnuplot_i.h"
using namespace std;
namespace GMNLFS=Giacomo_Monari_Numerical_Library_For_Simulations;
int main (int argc, char * const argv[]) {
ifstream dataFile("/Users/giacomomonari/Programmi C++/
lab3_1/3cr_1.txt");
if (dataFile.fail())
{
cout << "No data file!" << endl;
}
string dummy1;
getline(dataFile,dummy1);
vector<double> z(0);
vector<double> mv(0);
vector<double> s178(0);
vector<double> a150(0);
vector<double> las(0);
vector<double> lls(0);
vector<double> loglb(0);
vector<double> logp178(0);
char dummy2[19];
double currentVar;
int count = 0;
while(!dataFile.eof())
{
dataFile.ignore(19,*dummy2);
dataFile >> currentVar;
z.push_back(currentVar);
dataFile >> currentVar;
dataFile >> currentVar;
mv.push_back(currentVar);
dataFile >> currentVar;
s178.push_back(currentVar);
dataFile >> currentVar;
a150.push_back(currentVar);
dataFile >> currentVar;
las.push_back(currentVar);
dataFile >> currentVar;
lls.push_back(currentVar);
dataFile >> currentVar;
loglb.push_back(currentVar);
dataFile >> currentVar;
logp178.push_back(currentVar);
count++;
}
dataFile.close();
{
GMNLFS::DataAnalysis<vector<double>::iterator,double>
zAnalysis(z.begin(),z.end());
cout << "Max z = " << zAnalysis.GetMax() << endl;
cout << "Min z = " << zAnalysis.GetMin() << endl;
cout << "Average z = " << zAnalysis.GetAverage() << endl;
cout << "Variance of z = " << zAnalysis.GetVariance() << endl;
cout << "Standard Deviation of z = " << zAnalysis.GetStdDeviation()
<< endl;
cout << "Skewness of z = " << zAnalysis.GetSkewness() << endl;
cout << "Kurtosis of z = " << zAnalysis.GetKurtosis() << endl;
cout << " ------------------------------------- " << endl;
}
{
GMNLFS::DataAnalysis<vector<double>::iterator,double>
mvAnalysis(mv.begin(),mv.end());
cout << "Max mv = " << mvAnalysis.GetMax() << endl;
cout << "Min mv = " << mvAnalysis.GetMin() << endl;
cout << "Average mv = " << mvAnalysis.GetAverage() << endl;
cout << "Variance of mv = " << mvAnalysis.GetVariance() << endl;
cout << "Standard Deviation of mv = " <<
mvAnalysis.GetStdDeviation()
<< endl;
cout << "Skewness of mv = " << mvAnalysis.GetSkewness() << endl;
cout << "Kurtosis of mv = " << mvAnalysis.GetKurtosis() << endl;
cout << " ------------------------------------- " << endl;
}
{
GMNLFS::DataAnalysis<vector<double>::iterator,double>
s178Analysis(s178.begin(),s178.end());
cout << "Max s178 = " << s178Analysis.GetMax() << endl;
cout << "Min s178 = " << s178Analysis.GetMin() << endl;
cout << "Average s178 = " << s178Analysis.GetAverage() << endl;
cout << "Variance of s178 = " << s178Analysis.GetVariance() << endl;
cout << "Standard Deviation of s178 = " <<
s178Analysis.GetStdDeviation() << endl;
cout << "Skewness of s178 = " << s178Analysis.GetSkewness() << endl;
cout << "Kurtosis of s178 = " << s178Analysis.GetKurtosis() << endl;
cout << " ------------------------------------- " << endl;
}
{
GMNLFS::DataAnalysis<vector<double>::iterator,double>
a150Analysis(a150.begin(),a150.end());
cout << "Max a150 = " << a150Analysis.GetMax() << endl;
cout << "Min a150 = " << a150Analysis.GetMin() << endl;
cout << "Average a150 = " << a150Analysis.GetAverage() << endl;
cout << "Variance of a150 = " << a150Analysis.GetVariance() << endl;
cout << "Standard Deviation of a150 = " <<
a150Analysis.GetStdDeviation() << endl;
cout << "Skewness of a150 = " << a150Analysis.GetSkewness() << endl;
cout << "Kurtosis of a150 = " << a150Analysis.GetKurtosis() << endl;
cout << " ------------------------------------- " << endl;
}
{
GMNLFS::DataAnalysis<vector<double>::iterator,double>
lasAnalysis(las.begin(),las.end());
cout << "Max las = " << lasAnalysis.GetMax() << endl;
cout << "Min las = " << lasAnalysis.GetMin() << endl;
cout << "Average las = " << lasAnalysis.GetAverage() << endl;
cout << "Variance of las = " << lasAnalysis.GetVariance() << endl;
cout << "Standard Deviation of las = " <<
lasAnalysis.GetStdDeviation() << endl;
cout << "Skewness of las = " << lasAnalysis.GetSkewness() << endl;
cout << "Kurtosis of las = " << lasAnalysis.GetKurtosis() << endl;
cout << " ------------------------------------- " << endl;
}
{
GMNLFS::DataAnalysis<vector<double>::iterator,double>
llsAnalysis(lls.begin(),lls.end());
cout << "Max lls = " << llsAnalysis.GetMax() << endl;
cout << "Min lls = " << llsAnalysis.GetMin() << endl;
cout << "Average lls = " << llsAnalysis.GetAverage() << endl;
cout << "Variance of lls = " << llsAnalysis.GetVariance() << endl;
cout << "Standard Deviation of lls = " <<
llsAnalysis.GetStdDeviation() << endl;
cout << "Skewness of lls = " << llsAnalysis.GetSkewness() << endl;
cout << "Kurtosis of lls = " << llsAnalysis.GetKurtosis() << endl;
cout << " ------------------------------------- " << endl;
}
{
GMNLFS::DataAnalysis<vector<double>::iterator,double>
loglbAnalysis(loglb.begin(),loglb.end());
cout << "Max loglb = " << loglbAnalysis.GetMax() << endl;
cout << "Min loglb = " << loglbAnalysis.GetMin() << endl;
cout << "Average loglb = " << loglbAnalysis.GetAverage() << endl;
cout << "Variance of loglb = " << loglbAnalysis.GetVariance() <<
endl;
cout << "Standard Deviation of loglb = " <<
loglbAnalysis.GetStdDeviation() << endl;
cout << "Skewness of loglb = " << loglbAnalysis.GetSkewness() <<
endl;
cout << "Kurtosis of loglb = " << loglbAnalysis.GetKurtosis() <<
endl;
cout << " ------------------------------------- " << endl;
}
{
GMNLFS::DataAnalysis<vector<double>::iterator,double>
logp178Analysis(logp178.begin(),logp178.end());
cout << "Max logp178 = " << logp178Analysis.GetMax() << endl;
cout << "Min logp178 = " << logp178Analysis.GetMin() << endl;
cout << "Average logp178 = " << logp178Analysis.GetAverage() <<
endl;
cout << "Variance of logp178 = " << logp178Analysis.GetVariance() <<
endl;
cout << "Standard Deviation of logp178 = " <<
logp178Analysis.GetStdDeviation() << endl;
cout << "Skewness of logp178 = " << logp178Analysis.GetSkewness() <<
endl;
cout << "Kurtosis of logp178 = " << logp178Analysis.GetKurtosis() <<
endl;
cout << " ------------------------------------- " << endl;
vector<double> xAxeLogP178(50);
vector<double> yAxeLogP178(50);
logp178Analysis.CreateHistogram(xAxeLogP178.begin(),
xAxeLogP178.end(), yAxeLogP178.begin(), yAxeLogP178.end());
Gnuplot g;
g.set_style("boxes");
g.plot_xy(xAxeLogP178,yAxeLogP178,"luminosity distribution");
sleep(SLEEP_LGTH);
}
return 0;
}
Note that before returning that error message the program does
correctly its work (but returning a wrong graphic with gnuplot).
I'm using in this program an header I created, "dataAnalysis.h", that
in other programs hadn't problems... So I don't understand if it is
that header's fault... What could it be?
Giacomo
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]