Hello everyone,
I have a problem, I have a char ** called "buffer". I want to have the 'buffer' point to a number of char *'s which store up to "bufsize" characters. I use malloc to allocate the space which gives me the code:
nbufs = 8;
bufsize = 32;
char **buffer;
buffer = malloc(nbufs);
for(int i = 0; i<nbufs; i++){
buffer[i] = malloc(bufsize+1);
}
First off... is this right?
Now when I try to free the buffers I get an error.
If i try to free the buffer like this...
for(int i = 0; i<nbufs; i++){
free(buffer[i]);
}
I get this error at compile time:
*** glibc detected *** free(): invalid next size (fast): 0x0804a008 ***
Aborted
If I just ignore the for statement and try this...
free(buffer);
I get the error at compile time:
*** glibc detected *** free(): invalid next size (fast): 0x0804a008 ***
Aborted
Is my char ** buffer not malloc'd right? What am I missing? Thank you ahead of time for your help.