title: Lost connection to MySQL server when deleting initid->ptr, MySQL aggregate function (UDF)
body: <p>I created a MySQL aggregate UDF in C++.
  I am returning <code>char*</code> from the final function of MySQL aggregate UDF.
  In the <code>void xxx_deinit(UDF_INIT initid)</code> I am releasing any memory used by my function.
  I am releasing the memory by deleting the <code>init-&gt;ptr</code>.</p>
  <p>My deinit function:</p>
  <pre><code>extern &quot;C&quot; void xxx_deinit(UDF_INIT * initid)
  {
      delete initid-&gt;ptr;
  }
  </code></pre>
  <p>In the init function I am initialing the <code>ptr</code> like this:</p>
  <pre><code>extern &quot;C&quot; bool xxx_init(UDF_INIT * initid, UDF_ARGS * args, char* message)
  {
      const char*  demo = &quot;demo&quot;;
  
      initid-&gt;ptr = (char*) demo;
  
      return 0;
  }
  </code></pre>
  <p>I am able to create the UDF and install it in the MySQL server.
  After installing when I try to call the function, an error message pops up like this:</p>
  <pre><code>Error Code: 2013. Lost connection to MySQL server during query
  </code></pre>
  <p>But when I delete the line: <code>delete initid-&gt;ptr;</code> from the <code>xxx_deinit(UDF_INIT * initid)</code> function, I get the desired output.
  But I am guessing this is the wrong approach because it will lead to a memory leak.
  Also, the same statement: <code>delete initid-&gt;ptr;</code> doesn't generate error in case of simple UDF of return type <code>char*</code>.
  Can anyone tell me what am I doing wrong here?
  Any kind of help or suggestions will be of great help.
  thanks in advance.</p>
  <p>Can anyone help me solving this issue.</p>