finger

a simple finger client
Log | Files | Refs

commit 4688751e4ecf04b3af939d761097c679edd9dac2
parent cba6579eec0d0b19997551582e041e77142265e8
Author: Naveen Narayanan <zerous@nocebo.space>
Date:   Sat, 25 Sep 2021 16:51:58 +0200

Move malloc outside the loop

Diffstat:
Mfinger.c | 13+++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/finger.c b/finger.c @@ -71,6 +71,13 @@ main(int argc, char **argv) goto err1; } + msg = malloc(BUFSZ); + if (!msg) { + err = 1; + goto err2; + } + memset(msg, 0, BUFSZ); + for (p = res; p != NULL; p = p->ai_next) { sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); @@ -89,12 +96,6 @@ main(int argc, char **argv) } len = strlen(user); - msg = malloc(BUFSZ); - if (!msg) { - err = 1; - goto err3; - } - memset(msg, 0, BUFSZ); memcpy(msg, user, len); msg[len] = '\r'; msg[len+1] = '\n';