Note that there are some explanatory texts on larger screens.

plurals
  1. POmalloc and free issue
    primarykey
    data
    text
    <p>So I have this piece of code, I run it a couple of times:</p> <pre><code>void svnViewStatus() { FILE *file; int i, j, k, q=0, ok; char mystring[100000], *vect[100000], *var, last[12], first[12]; file = fopen("db_svnViewStatus.txt", "r"); if(file == NULL) { printf("error"); } else { i=1; while(fgets(mystring, 100000, file)) { if( i &gt; 1) { j=1; var = strtok(mystring, ";"); while(var != NULL) { if(j==3) { if(i == 2) { strcpy(first, var); } strcpy(last, var); } if(j == 2) { if(q != 0) { ok=1; for(k=0; k&lt;q; k=k+2) { if(strcmp(vect[k], var) == 0) { *vect[k+1]++; ok=0; } } if(ok == 1) { vect[q] = malloc(strlen(var)+1); strcpy(vect[q], var); vect[q+1] = malloc(sizeof(int)); *vect[q+1] = 1; q = q+2; } } else { vect[q] = malloc(strlen(var)+1); strcpy(vect[q], var); vect[q+1] = malloc(sizeof(int)); *vect[q+1] = 1; q = q+2; } } j++; var = strtok(NULL, ";"); } } i++; } } fclose(file); printf("nr: %d \n", i-2); printf("first: %s \n", first); printf("last: %s \n", last); for(i=0; i&lt;q; i = i+2) { printf("User %s: %d \n", *vect[i], *vect[i+1]); } for(i=0; i&lt;q; i=i+1) { free(vect[i]); } } </code></pre> <p>and in the db_svnViewStatus.db I have: </p> <pre><code>NumeRepo:CitateWoodyAllen;DataCreat:12 Nov 2011;Detinator:Ioana;Descriere:Citate ale faimosului regizor Woody Allen 1;Ioana;12 Nov 2011;Woody Allen;What if everything is an illusion and nothing exists? In that case, I definitely overpaid for my carpet. 2;Mihai;12 Nov 2011;Woody Allen;The lion and the calf shall lie down together but the calf won't get much sleep 3;Mihai;13 Nov 2011;Woody Allen;Eighty percent of success is showing up 4;Cristi;23 Nov 2011;Woody Allen;It is impossible to travel faster than the speed of light, and certainly not desirable, as one's hat keeps blowing off 5;Ioana;25 Nov 2011;Woody Allen;I had a terrible education. I attended a school for emotionally disturbed teachers. 6;Cristi;25 Nov 2011;Woody Allen;I will not eat oysters. I want my food dead. Not sick. Not wounded. Dead. </code></pre> <p>But I get this:</p> <p>"HEAP CORRUPTION DETECTED: after Normal block (#54) at 0x000032E90. CRT detected that the application wrote to memory after end of heap buffer."</p> <p>Any help?</p> <p>Also, should I use free after I allocate memory? Why? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload