salut,
en utilisant valgrid sur ce code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    char buffer[BUFF+1];
    memset(buffer,0,sizeof(buffer));
 
    char *HtmlContent = (char *)malloc(sizeof(char)+1);
 
    sprintf(HtmlContent," ");
   unsigned long long int total = 0;
 
    while((res = recv(sock,buffer,BUFSIZ,0))>0)
    {
 
        if(res>0)
        {
            total+=res;
        //  printf("res = %d ,total = %Ld\n",res,total);    
            if ((size>0)&&(total>size))
                break;
            HtmlContent = (char *)realloc(HtmlContent,sizeof(char)*(total+1));
            if(HtmlContent == NULL)
            {
                free(server);
                close(sock);
                return NULL;
            }
            strcat(HtmlContent,buffer);
        }
        memset(buffer,0,res);
    }
et l'erreur:
Address 0x4e47584 is 0 bytes after a block of size 2,948 alloc'd
==23331== at 0x4A06129: realloc (vg_replace_malloc.c:525)
==23331== by 0x4C0D55E: getHTTPInfo (www.c:428)
==23331== by 0x40092F: main (content.c:14)
et encore celle ci:
==24629== Invalid write of size 1
==24629== at 0x4A065DF: strcat (mc_replace_strmem.c:176)
==24629== by 0x4C0D5A3: getHTTPInfo (www.c:435)
j'ai beau lire et relire je ne vois pas ce qui cloche. quelqu'un pourait-il m'aider un tout petit peu? merci

je precise que le code marche 9/10, la seule fois ou il plante c'est justement au niveau de realloc.