Malloc Error To solve a Malloc Error I recommend for XCode Users to always activate the GuardMalloc feature for the Debugger. You can Access this Feature through the Run Options of your Application under the tab "Diagnostics". The Guard Malloc helps to find the exact Location where the Malloc Error is generated. Without it, it the Malloc Error will occur while running at Line which does not produce the mistake (like in my case line 207 was shown to throw the Error instead it was a completely other line). With a little bit more Debugging it showed, that The Error occured, because I tried to access a value of an array but the index was out of the Arrays bounds. (Temphist.size would be 38, it tried to access the value at 52). The Solution was, that the calculation of Bin was wrong instead of this: cvRound((n/360.f)+ori[k]it should be cvRound((n/360.f)*ori[k]so instead of the value 52 the result would be 8.8