Re: How to check if DTD or Doc is loaded ?



You set *dtd to nullptr, and then at the next call test if it's NULL. I wouldn't expect that to be a problem, but perhaps it is. Is NULL the same as nullptr? Why not just

if (!*dtd) {
  return;
}

Den 2017-11-10 kl. 20:31, skrev Mat D:
Thank you very much for this great explanation !

This code perfectly works for freeing  xmlDocPtr but not for xmlDtdPtr

I created a method to free loaded did (I cannot free just after the validating because I use it multiple times against different documents) which do the following :


if(*dtd == NULL){
  return;
}
// Force clear memory DTD loaded
xmlFreeDtd(*dtd);
*dtd = nullptr;


It works great!  But if I call this functions twice or more I got an error "3400 segmentation fault" which is not the expected result ;) .

I did the same for xmLdocPtdr an I can call it's function twice without error.

I do not understand the real problem :s

2017-11-07 9:56 GMT+01:00 Kjell Ahlstedt <kjellahlstedt gmail com>:
Den 2017-11-06 kl. 15:06, skrev Mat D:
Hi everyone,

I am using the c++ Libxml Lib & I want to free DTD & xml loaded ONLY if they are .
Because if I use those functions twice it crash the lib because documents have already been free :

xmlFreeDtd();
xmlFreeDoc();

How to check if a dtd/doc is loaded ?

I tried things as: 
if(dtdPtr->type == XML_DTD_NODE){
  std::cout << "free memory now .." << std::endl;
  xmlFreeDtd(dtdPtr);
}
But it does not work :s
Thanks by advance for help!!

If you use the C++ library, libxml++, don't call xmlFreeDtd() or xmlFreeDoc() yourself. Let the C++ classes do that. If you want to free a DTD or a document, delete the corresponding xmlpp::Dtd or xmlpp::Document instance.

If you use the C library, libxml2, directly, clear the pointer after the call to xmlFreeDtd() or xmlFreeDoc().
  xmlFreeDoc(mydoc);
  mydoc = nullptr;  // mydoc = NULL; if you use a C compiler.
Any access to freed memory is an error.

/Kjell




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]