fixed read_socket memory problems
This commit is contained in:
parent
7b51acba52
commit
e77e578be8
@ -65,14 +65,14 @@ int main(void)
|
|||||||
|
|
||||||
char *read_socket(int socket)
|
char *read_socket(int socket)
|
||||||
{
|
{
|
||||||
long content_size;
|
long content_size = 0;
|
||||||
char *content;
|
char *content = NULL;
|
||||||
|
|
||||||
//COUNT content_size
|
//COUNT content_size
|
||||||
ioctl(socket, FIONREAD, &content_size);
|
ioctl(socket, FIONREAD, &content_size);
|
||||||
|
|
||||||
//ALLOCATE
|
//ALLOCATE
|
||||||
content = why2_calloc(content_size, sizeof(char));
|
content = why2_calloc(content_size + 1, sizeof(char));
|
||||||
|
|
||||||
//READ
|
//READ
|
||||||
if (read(socket, content, content_size) != content_size) why2_die("Reading socket failed!");
|
if (read(socket, content, content_size) != content_size) why2_die("Reading socket failed!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user