Freeing memory for struct.name (debug error: HEAP CORRUPTION DETECTED)
<p>I'm creating dynamic arrays with the length of a name inputed by the user, but when I want to <code>free()</code> the memory allocated with <code>malloc()</code> it's giving me a "Debug error"</p>

<pre><code>typedef struct
{
    char *nombre;
    float nota;
} tficha;

tficha leeFicha() 
{
    char nombreTam[100]; 
    int tamNombre;      
    tficha ficha;       
    scanf("%s",nombreTam); 
    tamNombre=strlen(nombreTam); 
    ficha.nombre=(char *)malloc(tamNombre*sizeof(char)); 
    strcpy(ficha.nombre,nombreTam); 
    free(ficha.nombre); // Here is giving me a Debug Error (HEAP CORRUPTION DETECTED: after Normal block (#166) at 0x0065C450. CRT detected that the application wrote to memory after end of heap buffer.)
    return ficha;       
}
</code></pre>

<p>How can I free <code>ficha.nombre</code> without errors?</p>