In the same file I have two routines. The first will store some bytes from one file. The other will give this information to routines that will process that information.
boolean
adin_memory(char* buffer, int size_chunck, int end_flag){
    real_data=(SP16 *)malloc(size_chunck); //real_data -->global
    memcpy(&(real_data[0]),&(buffer[0]),size_chunck);
    pos_write += size_chunck;
    global_size = size_chunck;
    global_end_flag = end_flag;
    //end_flag = 1 --> end of Stream
    //end_flag = 0 --> Streaming
    return TRUE;
}
To prevent the possibility of leaking I am using malloc. But this routine is called several times. So, after some repetitions of adin_memory and adin_read (where will be free), I think the memory starts to fragment (I can see a leak with the size of the input file in task manager - increment of RAM). Is that right? How can I prevent this? To see this leak I put one breakpoint at the beginning and at the end of adin_memory an look at task manager.
int
adin_read(SP16 *buf, int sampnum)
{
  FILE *fp;
  int cnt = 0;
  fp = gfp;
  //(.......)
    if(global_end_flag == 1 || pos_write == pos_read){ return -1;}
    for(i = pos_read/sizeof(SP16); i <= sampnum; i++){
         if(i >= pos_write/sizeof(SP16)) {              
             cnt = i;
             //(....)
             break;
         }
         buf[i] = real_data[i];
     }
     pos_write = 0; 
     //(....)
     free(real_data);
     return cnt;
}