segmentation fault cause by delete[] while writing to a file
<p>I'm trying to write to a file and i get a segmentation fault when i delete the allocated memory. I don't understant what is the problem, please help:</p>

<pre><code>void writeToLog(string msg) {

    int len = msg.size()+1;
        char *text = new char(len);
    strcpy(text,msg.c_str());
    char* p = text;
    for(int i=0; i&lt;len; i++){
        fputc(*p, _log) ;
        p++;
    }
    delete[] text;   //THIS IS WHERE IT CRASHES
}
</code></pre>

<p>I also tried without the <code>[ ]</code> but then i get 
<code>*** glibc detected *** ./s: free(): invalid next size (fast): 0x09ef7308 ***</code></p>

<p>So what is the problem?</p>

<p>Thanks!</p>
