Skip to contentSkip to conversation

Fix: FD leak in accept error handling

PATCH Mathieu Desnoyers 2 participants 3 messages Oct 4, 2014 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Bump.

----- Original Message -----

Quoted 66 lines

From: "Mathieu Desnoyers" <[email protected]>
To: [email protected]
Cc: [email protected], "Mathieu Desnoyers" <[email protected]>
Sent: Saturday, September 27, 2014 7:49:22 PM
Subject: [PATCH lttng-tools] Fix: FD leak in accept error handling

*** CID 1241799: Resource leak (RESOURCE_LEAK) /src/common/sessiond-comm/inet.c: 324 in lttcomm_accept_inet_sock() 318
319 end:
320 return new_sock;
321
322 error:
323 free(new_sock);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1241799: Resource leak (RESOURCE_LEAK)
Handle variable "new_fd" going out of scope leaks the handle.

324 return NULL;
325 }
326
327 /*
328 * Make the socket listen using LTTNG_SESSIOND_COMM_MAX_LISTEN.
329 */

---
 src/common/sessiond-comm/inet.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/common/sessiond-comm/inet.c +9 -1
index cf06ecb..4e34ad0 100644
@@ -272,7 +272,7 @@ error_connect:
 LTTNG_HIDDEN
 struct lttcomm_sock *lttcomm_accept_inet_sock(struct lttcomm_sock *sock)
 {
-	int new_fd;
+	int new_fd, closeret;
 	socklen_t len;
 	struct lttcomm_sock *new_sock;
 	unsigned long timeout;
@@ -305,10 +305,18 @@ struct lttcomm_sock *lttcomm_accept_inet_sock(struct
 lttcomm_sock *sock)
 
 		ret = lttcomm_setsockopt_rcv_timeout(new_fd, timeout);
 		if (ret) {
+			closeret = close(new_fd);
+			if (closeret) {
+				PERROR("close");
+			}
 			goto error;
 		}
 		ret = lttcomm_setsockopt_snd_timeout(new_fd, timeout);
 		if (ret) {
+			closeret = close(new_fd);
+			if (closeret) {
+				PERROR("close");
+			}
 			goto error;
 		}

}
--
2.1.0

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

That has been fix.

commit 475cd9fa36ab2ad108f94bb8292bdcdbbbc6e38f

This was a coverity issue fixed on sept. 30th.

David

Quoted 61 lines · Mathieu Desnoyers

Bump.

----- Original Message -----

Quoted 58 lines

From: "Mathieu Desnoyers" <[email protected]>
To: [email protected]
Cc: [email protected], "Mathieu Desnoyers" <[email protected]>
Sent: Saturday, September 27, 2014 7:49:22 PM
Subject: [PATCH lttng-tools] Fix: FD leak in accept error handling

*** CID 1241799: Resource leak (RESOURCE_LEAK) /src/common/sessiond-comm/inet.c: 324 in lttcomm_accept_inet_sock() 318
319 end:
320 return new_sock;
321
322 error:
323 free(new_sock);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1241799: Resource leak (RESOURCE_LEAK)
Handle variable "new_fd" going out of scope leaks the handle.

324 return NULL;
325 }
326
327 /*
328 * Make the socket listen using LTTNG_SESSIOND_COMM_MAX_LISTEN.
329 */

---
 src/common/sessiond-comm/inet.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/common/sessiond-comm/inet.c +8 -1
index cf06ecb..4e34ad0 100644
@@ -272,7 +272,7 @@ error_connect:
 LTTNG_HIDDEN
 struct lttcomm_sock *lttcomm_accept_inet_sock(struct lttcomm_sock *sock)
 {
-	int new_fd;
+	int new_fd, closeret;
 	socklen_t len;
 	struct lttcomm_sock *new_sock;
 	unsigned long timeout;
@@ -305,10 +305,18 @@ struct lttcomm_sock *lttcomm_accept_inet_sock(struct
 lttcomm_sock *sock)
 
 		ret = lttcomm_setsockopt_rcv_timeout(new_fd, timeout);
 		if (ret) {
+			closeret = close(new_fd);
+			if (closeret) {
+				PERROR("close");
+			}
 			goto error;
 		}
 		ret = lttcomm_setsockopt_snd_timeout(new_fd, timeout);
 		if (ret) {
+			closeret = close(new_fd);
+			if (closeret) {
+				PERROR("close");
Quoted 13 lines
Quoted 8 lines
src/common/sessiond-comm/inet.c +1 -0
+			}
 			goto error;
 		}

}
--
2.1.0

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): 20141004132739.GA6774@thessa

#5 lore raw

OK, thanks! I did not see any reply to the email, this is why I was wondering what happened there.

----- Original Message -----

Quoted 92 lines

From: "David Goulet" <[email protected]>
To: "Mathieu Desnoyers" <[email protected]>
Cc: [email protected]
Sent: Saturday, October 4, 2014 9:27:39 AM
Subject: Re: [PATCH lttng-tools] Fix: FD leak in accept error handling

That has been fix.

commit 475cd9fa36ab2ad108f94bb8292bdcdbbbc6e38f

This was a coverity issue fixed on sept. 30th.

David

Quoted 76 lines · Mathieu Desnoyers

Bump.

----- Original Message -----

Quoted 65 lines

From: "Mathieu Desnoyers" <[email protected]>
To: [email protected]
Cc: [email protected], "Mathieu Desnoyers" <[email protected]>
Sent: Saturday, September 27, 2014 7:49:22 PM
Subject: [PATCH lttng-tools] Fix: FD leak in accept error handling

*** CID 1241799: Resource leak (RESOURCE_LEAK) /src/common/sessiond-comm/inet.c: 324 in lttcomm_accept_inet_sock() 318
319 end:
320 return new_sock;
321
322 error:
323 free(new_sock);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1241799: Resource leak (RESOURCE_LEAK)
Handle variable "new_fd" going out of scope leaks the handle.

324 return NULL;
325 }
326
327 /*
328 * Make the socket listen using LTTNG_SESSIOND_COMM_MAX_LISTEN.
329 */

---
 src/common/sessiond-comm/inet.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/common/sessiond-comm/inet.c +9 -1
index cf06ecb..4e34ad0 100644
@@ -272,7 +272,7 @@ error_connect:
 LTTNG_HIDDEN
 struct lttcomm_sock *lttcomm_accept_inet_sock(struct lttcomm_sock *sock)
 {
-	int new_fd;
+	int new_fd, closeret;
 	socklen_t len;
 	struct lttcomm_sock *new_sock;
 	unsigned long timeout;
@@ -305,10 +305,18 @@ struct lttcomm_sock
 *lttcomm_accept_inet_sock(struct
 lttcomm_sock *sock)
 
 		ret = lttcomm_setsockopt_rcv_timeout(new_fd, timeout);
 		if (ret) {
+			closeret = close(new_fd);
+			if (closeret) {
+				PERROR("close");
+			}
 			goto error;
 		}
 		ret = lttcomm_setsockopt_snd_timeout(new_fd, timeout);
 		if (ret) {
+			closeret = close(new_fd);
+			if (closeret) {
+				PERROR("close");
+			}
 			goto error;
src/common/sessiond-comm/inet.c +0 -1
 		}
 	}
--
Quoted 3 lines

2.1.0

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com