I have following code in which I am getting "Heap corruption detected" message while trying to freeing memory allocated while using strdup().
Please let me know what I am missing?Code:#include <iostream> #include <string> #include "Check.h" static void main() { for (int i = 0;i< 5 ;i++) { char cname[32]; cname = GetGroupName()//These function assigns name here bool exist; exist = GetGroupStatus(cname); } } bool GetGroupStatus(char *cname) { char * cTemp = NULL; cTemp = _strdup(cname); bool bGrpStatus; size_t found; //some code here std::string sTemp = cTemp; found = sTemp.find("GROUP"); if (found != string::npos) bGrpStatus = true; else bGrpStatus = false; if (cTemp != NULL) free(cTemp); //These causes heap corruption detected message when control comes here second time return bGrpStatus; }




Reply With Quote