title: PostgreSQL: The ereport function does not clear the stack before exiting
body: <p>I'm just trying to exit the function with an error, however the stack is not cleared.
  I wrote a Foo class and create logs in the destructor. However, nothing is logged<br></p>
  <pre><code>#pragma once
  
  #include &quot;Logger.h&quot;
  inline auto&amp; logger = Logger::getInstance();
  
  extern &quot;C&quot;
  {
  
  #include &quot;postgres.h&quot;
  #include &quot;fmgr.h&quot;
  
  #include &quot;miscadmin.h&quot;
  #include &quot;catalog/pg_authid.h&quot;
  #include &quot;utils/syscache.h&quot;
  #include &quot;utils/builtins.h&quot;
  
  PG_FUNCTION_INFO_V1(simpleFuntions);
  Datum simpleFuntions(PG_FUNCTION_ARGS);
  
  }
  </code></pre>
  <p>test.cpp</p>
  <pre><code>#include &quot;test.h&quot;
  
  extern &quot;C&quot;
  {
      PG_MODULE_MAGIC;
  }
  class Foo
  {
      public:
      Foo(){logger.log(&quot;START&quot;);};
      ~Foo(){logger.log(&quot;TEST IS CORRECT!&quot;);};
  };
  
  Datum simpleFuntions(PG_FUNCTION_ARGS)
  {
          Foo che;
          ereport(ERROR,
              (
                  errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                  errmsg(&quot;ERROR&quot;)
              )
          );
   
          FlushErrorState();
      
      PG_RETURN_TEXT_P(cstring_to_text(&quot;HelloWorld&quot;));
  }
  </code></pre>
  <p>After function execution, in logs file I see only &quot;START&quot;.</p>