Fix: v6 socket. Free line at end

This commit is contained in:
Tim Schubert 2018-10-29 11:40:29 +01:00
parent 4d7d96872a
commit 57a3406522

View file

@ -270,7 +270,7 @@ int connectclient(struct addrinfo *ainfo) {
int client() { int client() {
char buf[BUFLEN]; char buf[BUFLEN];
size_t nullsize = 0; size_t nullsize = 0;
char *line = NULL; char *line = (char *) malloc(BUFLEN);
while (getline(&line, &nullsize, stdin) != -1) { while (getline(&line, &nullsize, stdin) != -1) {
unsigned int num1; unsigned int num1;
unsigned int num2; unsigned int num2;
@ -293,10 +293,6 @@ int client() {
perror("send"); perror("send");
continue; continue;
} }
free(line);
line = NULL; // so getline allocates a buffer for us
memset(buf, 0, BUFLEN); memset(buf, 0, BUFLEN);
ssize_t re_bytes_c = recv(SOCKFD, buf, sizeof buf, 0); ssize_t re_bytes_c = recv(SOCKFD, buf, sizeof buf, 0);
if (re_bytes_c == -1) { if (re_bytes_c == -1) {
@ -305,6 +301,7 @@ int client() {
} }
printf("%s", buf); printf("%s", buf);
} }
free(line);
return 0; return 0;
} }
@ -336,7 +333,7 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} else { } else {
CLIENT = 0; CLIENT = 0;
afamiliy = AF_UNSPEC; afamiliy = AF_INET6;
flags |= AI_PASSIVE; flags |= AI_PASSIVE;
if (argc > 1) { if (argc > 1) {
port = argv[1]; port = argv[1];