I tried dataPoolBuffer = realloc(dataPoolBuffer, sizeof(char)*(dataPoolSize)); already, but Xcode reports:assigning to 'char *' from imcompatible type 'void'.
I create a class:
class solutionBuffer{ 
private:
char * dataPoolBuffer;
char * consumerBuffer;
char * flagBuffer;
int dataPoolSize;
int consumerBufferSize;
mutex safe;
public:
solutionBuffer(){
    safe.lock();
    dataPoolSize = 0;
    consumerBufferSize = 0;
    
    dataPoolBuffer = (char*)malloc(sizeof(char)*1);
    consumerBuffer = (char*)malloc(sizeof(char)*1);
    flagBuffer = (char*)malloc(sizeof(char)*1);
    
}
int add(char* data, int length)
{
   
    dataPoolSize += length;
    
    realloc(dataPoolBuffer, sizeof(char)*(dataPoolSize));
    
    realloc(flagBuffer, sizeof(char)*(dataPoolSize));
    
    memcpy(dataPoolBuffer + dataPoolSize - length, data, sizeof(char)*(length));
    
    return 0;
}
~solutionBuffer(){
    printf("%d",strlen(dataPoolBuffer));
    free(dataPoolBuffer);
    free(consumerBuffer);
    free(flagBuffer);
    safe.unlock();
}
};
Every time when we call .add function, it will realloc memory for the variable. However, when I do that in main():
char data[] = "0123456789";
char data2[] = "01234567890123456789";
solutionBuffer buffer;
buffer.add(data, 10);
buffer.add(data2, 20);
The xoce shows:pointer being freed was not allocated in ~solutionBuffer() when it was trying to free dataPoolBuffer .
Why it does like that? How to fix that ?
 
     
     
     
    