Debug assertion failed on class destructor
<p>I'm doing a dll in c++ and I get this error the second time I call a function:</p>

<p><em>Debug Assertion Failed Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)</em></p>

<p>I did some research and this seems to happen when I <code>delete</code> an object which I didn't <code>new</code></p>

<p>Here is the code I think is failing</p>

<pre><code>class tFont
{
public:
    tFont(char chars[], __int64 cods[], int count);
    ~tFont();


    int fontCount = 0;
    char* characters = NULL;
    long long* codes = NULL;

    std::vector&lt;std::pair&lt;char,long long&gt;&gt; exceptions;


    char getCharacter(long long code);


};

tFont::tFont(char chars[], long long cods[], int count)
{
    characters = new char[count];
    codes = new long long[count];
    fontCount = count;

    for (int i = 0; i &lt; count; i++)
    {
        characters[i] = chars[i];
        codes[i] = cods[i];
    }


}


tFont::~tFont()
{

        delete[] characters;
        delete[] codes;
}
</code></pre>

<p>Visual studio stops in <code>delete[] characters;</code> after the error.</p>

<p>I tryied this without any luck</p>

<pre><code>if (characters != NULL)
{
    delete[] characters;
}
if (codes != NULL)
{
    delete[] codes;
}
</code></pre>

<p>I only create one instace of this class as a static object</p>

<pre><code>tFont* getCapFont()
{
    static tFont *capFont = NULL;

    if (capFont == NULL)
    {
        char characters[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        long long codes[] = { 241136, 441, 183861, 102321, 45836, 5955, 19305, 7871, 220321, 102286 };
        int fontCount = 10;

        capFont = new tFont(characters, codes, fontCount);
        pair&lt;char, long long&gt; e;
        e.first = '0';
        e.second = 24045;

        capFont-&gt;exceptions.push_back(e);
    }

    return capFont;
} 
</code></pre>

<p>Why is the destructor called even if I never do <code>delete capFont</code></p>

<p>Thank you!</p>

<p><strong>Edit2</strong>: I did as 'jarmod' said and the moment the error is thrown is when this function ends</p>

<p><code>void analysis::singleLineTextReader(tImage img, char result[], tFont font)</code></p>

<p>I said this happend the second time I call the function, it's possible that when <code>singleLineTextReader</code> ends calls the destructor of its parameter <code>font</code>? Which is the static object described above</p>