I am having errors in string assignment here. This is a function we coded for storing data fetched from a url. edit : datanode structure
struct node
{
string url;
std::string* data;
struct node* next;
struct node* prev;
};
void RandomCache::cachePage(string* page_data, string url)
{
datanode *page_node= (datanode*)malloc(sizeof(datanode));
page_node->url = url;
page_node->data = page_data;
page_node->next=NULL;
page_node->prev=NULL;
insertNode(page_node);
}
the line page_node->url = url is causing Double free or corruption, the data is passed by value, and not by reference. could anybody point out whats going wrong?
Thank you, I made the structure into a class, and the problem is completely resoluctved. Thanks! but I am still wondering about this, as to why structure memory management with malloc is problamatic in C++. structures are used very frequently in c++.