Skip to content

Commit f7f1cdd

Browse files
Fixed: Explicitly close socket on exit instead of relying on os to do it
Server may have to wait additionally to detect that client is gone and good practice to clean up resources as soon as possible. https://unix.stackexchange.com/questions/386536/when-how-does-linux-decides-to-close-a-socket-on-application-kill https://stackoverflow.com/questions/54053329/why-does-a-client-not-close-its-socket
1 parent 9df1baf commit f7f1cdd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

termux-am.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ int main(int argc, char* argv[]) {
101101
memset(tmp, '\0', sizeof(tmp));
102102
if (! recv_part(fd, tmp, sizeof(tmp)-1)) {
103103
fputs("Exit code too long", stderr);
104-
exit(1);
104+
close(fd);
105+
return 1;
105106
}
106107
errno = 0;
107108
exit_code = strtol(tmp, NULL, 10);
108109
if (errno != 0) {
109110
perror("Exit code not a valid number");
110-
exit(1);
111+
close(fd);
112+
return 1;
111113
}
112114
}
113115

@@ -131,5 +133,7 @@ int main(int argc, char* argv[]) {
131133
} while (!ret);
132134
}
133135

136+
close(fd);
137+
134138
return exit_code;
135139
}

0 commit comments

Comments
 (0)