Pointers and malloc
Hi, I just have one quick question.
I am doing something like this:
char *buf = malloc(10);
int file_descriptor = ... // just some file descriptor to read from
read(file_descriptor, buf, 9);
buf += 5;
Now the question is, when I call free(buf), does it free up all 10 bytes of memory that were allocated? Or only the 5 bytes following the current address that buf is pointing to?
I'm pretty sure that it will free 10 bytes but will free them starting at the point 5 from where you allocated them which could be very bad. But someone should probly confirm that
It will free any memory allocated with it, so all 10 bytes.