|
-
Jul 14th, 2003, 10:54 AM
#1
Thread Starter
Lively Member
The buffer when using recv
Hi.
All examples I have seen that use recv (in C wich is what I use) has had the buffer (that is filled up with recv) declared as:
char buffer[256];
I have done the following:
char *buffer=NULL;
buffer=malloc((BUFFSIZE)*sizeof(char));
and it all seem to work fine until the end of my function where I try to free the allocated memory with:
free(buffer);
Then the program buggs out on me.
Since I´m running MS VC++ I´ve done some debugging on it but haven´t found out why this is happeninig. buffer is allocated and contains info when trying to do the free().
So I wonder if it might be so that recv messes up my allocated buffer since I did get it thru malloc?
Or do anyone have another point of view?
-
Jul 14th, 2003, 12:14 PM
#2
Frenzied Member
This runs error free on my system using straight ansi C:
Code:
#include <stdlib.h>
#define BUFFSIZE 256
int main(int argc, char *argv[]){
char * buffer=NULL;
buffer=malloc(BUFFSIZE * sizeof(char));
memset(buffer, 0x00, (BUFFSIZE * sizeof(char)) );
free(buffer);
}
You have to be diddling with buffer somewhere, or dereferencing it:
buffer=NULL;
someplace else in your code
-
Jul 14th, 2003, 01:13 PM
#3
Thread Starter
Lively Member
You did not call recv.
I wonderd if that messed things up or not.
-
Jul 14th, 2003, 02:32 PM
#4
Frenzied Member
If you're talking about sockets (winsock), recv() does not invalidate the buffer pointer.
You have to be doing something to the pointer yourself, in your code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|