From: Jesper Juhl Date: Wed, 8 Aug 2012 18:56:14 +0000 (+0200) Subject: doc: getdelays.c: remember to close() socket on error in create_nl_socket() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0de4b95409367f5012ff5be7fd3785dc11c6cda8;p=GitHub%2Fexynos8895%2Fandroid_kernel_samsung_universal8895.git 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 Signed-off-by: Jiri Kosina --- diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c index f6318f6d7baf..6f706aca2049 100644 --- a/Documentation/accounting/getdelays.c +++ b/Documentation/accounting/getdelays.c @@ -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));