title: TidyHtml not working properly in C++
body: <p>I am using TidyHtml to clean up html files in my application in a Linux envorment. I do realize that that libtidy is a C library.  I did include it in the extern "C"{} syntax as indicated in my code. This is the example from the TidyHtml website adapted by me to use in a C++ example and I added the printf() function in conditions. </p>
  
  <p>There are two problems. The first starting with <code>tidyOptSetBool()</code> which fails and the <code>printf("%s\n", "1");</code> line is never reached.  The second is </p>
  
  <pre><code>tidyBufFree( &amp;output );
  tidyBufFree( &amp;errbuf );
  </code></pre>
  
  <p>lines cause a Segmentation fault (core dumped).</p>
  
  <p>This is the full code example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;tidy.h&gt;
  #include &lt;tidybuffio.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  using namespace std;
  
  extern "C" {
      int tidyHtml(){
          const char* input = "&lt;title&gt;Foo&lt;/title&gt;&lt;p&gt;Foo!";
          TidyBuffer output = {0};
          TidyBuffer errbuf = {0};
          int rc = -1;
          Bool ok;
  
          TidyDoc tdoc = tidyCreate();                     // Initialize "document"
          printf( "Tidying:\t%s\n", input );
  
          ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
          if ( ok ){
              rc = tidySetErrorBuffer( tdoc, &amp;errbuf );      // Capture diagnostics
              printf("%s\n", "1");
          }
  
          if ( rc &gt;= 0 ){
          rc = tidyParseString( tdoc, input );           // Parse the input
              printf("%s\n", "2");
          }
          if ( rc &gt;= 0 ){
          rc = tidyCleanAndRepair( tdoc );               // Tidy it up!
              printf("%s\n", "3");
          }
          if ( rc &gt;= 0 ){
          rc = tidyRunDiagnostics( tdoc );               // Kvetch
              printf("%s\n", "4");
          }
          if ( rc &gt; 1 ){                                    // If error, force output.
          rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
              printf("%s\n", "5");
          }
          if ( rc &gt;= 0 ){
          rc = tidySaveBuffer( tdoc, &amp;output );          // Pretty Print
              printf("%s\n", "6");
          }
  
          if ( rc &gt;= 0 )
          {
          if ( rc &gt; 0 )
            printf( "\nDiagnostics:\n\n%s", errbuf.bp );
          printf( "\nAnd here is the result:\n\n%s", output.bp );
          }
          else
          printf( "A severe error (%d) occurred.\n", rc );
  
          tidyBufFree( &amp;output );
          tidyBufFree( &amp;errbuf );
          tidyRelease( tdoc );
          return rc;
      }
  }
  
  
  int main(int argc, char *argv[]){
      tidyHtml();
  }
  </code></pre>
  
  <p>Here is my complie statement <code>g++ -o main main2.cpp -ltidy</code> which reports 0 errors.</p>
  
  <p>and this is output when the application is run:</p>
  
  <pre><code>Tidying:    &lt;title&gt;Foo&lt;/title&gt;&lt;p&gt;Foo!
  A severe error (-1) occurred.
  Segmentation fault (core dumped)
  </code></pre>