--- recvfile.c.orig 2013-07-17 19:50:43.587919082 -0700 +++ recvfile.c 2013-07-17 19:51:51.016918916 -0700 @@ -260,6 +260,11 @@ } old_flags = fcntl(sockfd, F_GETFL, 0); + if (old_flags == -1) { + free(buffer); + return -1; + } + if (set_blocking(sockfd, true) == -1) { free(buffer); return -1;