I am calling this code snippet inside a thread. But I'm getting memory leak.Is it due to continuous opening and closing of the File?If so, how can i solve this issue?
if(g_readFromDataFile == TRUE)
{
xmlDocPtr file = NULL;
xmlInitParser();
file = xmlReadFile("DataFile.xml",NULL,XML_PARSE_NOBLANKS);
xmlFreeDoc(file);
xmlCleanupParser();
}
I tried calling this code inside a while(1) loop outside this thread but didn't come across any memory leak.
Adding more details...
The thread is being created inside a function and is running continuously without a close.Inside this thread if the global variable is set 1 i should Read values from the file also i need to use another function to update parameters into the file.But since i got memory leak i cut down the entire code to find the source and found that leak happens even if the code is only to open and close.Is this an issue with the thread?
If you are reading the same file every time then just open it once at the beginning and close it when you are finally done (may be just before exiting the program). You will need to pass the file descriptor to functions which read the file. There is no need to keep opening and closing the file every time a file read is needed. May be you will need to change your code for this.