<p>I have been working on some legacy C++ code that uses variable length structures (TAPI), where the structure size will depend on variable length strings. The structures are allocated by casting array <code>new</code> thus:</p>

<pre class="lang-cpp prettyprint-override"><code>STRUCT* pStruct = (STRUCT*)new BYTE[sizeof(STRUCT) + nPaddingSize];
</code></pre>

<p>Later on however the memory is freed using a <code>delete</code> call:</p>

<pre class="lang-cpp prettyprint-override"><code>delete pStruct;
</code></pre>

<p>Will this mix of array <code>new[]</code> and non-array <code>delete</code> cause a memory leak or would it depend on the compiler?  Would I be better off changing this code to use <code>malloc</code> and <code>free</code> instead?</p>

Yes that may, since your allocating with new[] but deallocating with delelte, yes malloc/free is safer here, but in c++ you should not use them since they won't handle (de)constructors.
Also your code will call the deconstructor, but not the constructor. For some structs this may cause a memory leak (if the constructor allocated further memory, eg for a string)
Better would be to do it correctly, as this will also correctly call any constructors and deconstructors
```
```
STRUCT* pStruct = new STRUCT;
...
delete pStruct;
```
```