I have an issue regarding freeing memory as under:
string points; // some points sequences
char* charPoints = (char*)malloc((points.length() +1) * sizeof(char));
//do something
free(charPoints);
Even then after freeing memory is leaked when checked with instruments
The pointer you pass to
freemust be the same one which returned bymalloc. If you pass a different pointer it will result in a undefined behavior. Take a copy of the pointer before you do the operation such as incrementing thecharPointsand then pass this original pointer tofreefunction to properly release memory.