Skip to content

Commit

Permalink
doc: getdelays.c: remember to close() socket on error in create_nl_so…
Browse files Browse the repository at this point in the history
…cket()

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 <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
  • Loading branch information
jjuhl authored and Jiri Kosina committed Sep 1, 2012
1 parent 5ffd27f commit 0de4b95
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Documentation/accounting/getdelays.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ static int create_nl_socket(int protocol)
if (rcvbufsz)
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
&rcvbufsz, sizeof(rcvbufsz)) < 0) {
fprintf(stderr, "Unable to set socket rcv buf size "
"to %d\n",
fprintf(stderr, "Unable to set socket rcv buf size to %d\n",
rcvbufsz);
return -1;
goto error;
}

memset(&local, 0, sizeof(local));
Expand Down

0 comments on commit 0de4b95

Please sign in to comment.