Skip to content

Commit 0de4b95

Browse files
jjuhlJiri Kosina
authored andcommitted
doc: getdelays.c: remember to close() socket on error in create_nl_socket()
If the call to setsockopt() fails in Documentation/accounting/getdelays.c::create_nl_socket() we return -1 without closing the socket, thus leaking it when the 'fd' variable goes out of scope. Easily fixed by just jumping to the 'error' label instead of returning since we do the proper cleanup there. While I was there I noticed that the error message that is printet if setsockopt() fails was broken over two lines - put that on a single line so it is easier to grep for. Signed-off-by: Jesper Juhl <jj@chaosbits.net> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 5ffd27f commit 0de4b95

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

‎Documentation/accounting/getdelays.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ static int create_nl_socket(int protocol)
9898
if (rcvbufsz)
9999
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
100100
&rcvbufsz, sizeof(rcvbufsz)) < 0) {
101-
fprintf(stderr, "Unable to set socket rcv buf size "
102-
"to %d\n",
101+
fprintf(stderr, "Unable to set socket rcv buf size to %d\n",
103102
rcvbufsz);
104-
return -1;
103+
goto error;
105104
}
106105

107106
memset(&local, 0, sizeof(local));

0 commit comments

Comments
 (0)