c++ - " malloc error pointer being freed was not allocated " error only in simulator: -
when debug on actual devices, there no error, when use simulator, xcode's debugger console displays following error when running:
malloc: *** error object 0xaaaaaaaa: pointer being freed not allocated *** set breakpoint in malloc_error_break debug
the error happens @ same line, in constructor of class:
segment *segment = new segment(0.0,0.0,3.0,1.3,10); this->segments.push_back(segment); // malloc error @ line
my segment class:
class segment { private: float ajc; float frl; std::unordered_map<int,int> jgrc; std::vector<int> lorb; public: std::tuple<float,float> getmjt(); float getbuw(); …. segment(float a, float f,float g, float lo, float u){ …… }; };
on simulator, regardless of ios version, error appears. on devices, regardless of version, there no error.
i have heard rule of 3, in case don't think need apply because default compiler supplied code should work (unless i'm mistaken). what doing wrong, , how can fix ? since there no error reported on devices, should ignore ?
first put null check avoid run time error. tried pseudo code on vs , seemed work. hope vector similar.
segment *segment = new segment(0.0, 0.0, 3.0, 1.3, 10); std::vector<segment*> vec; if (null != segment) vec.push_back(segment);
i think there problem simulator not working fine.
Comments
Post a Comment