Skip to contentSkip to conversation

test/telemetry: fix socket resource leak

PATCH Applied Ciara Power 3 participants 3 messages Oct 13, 2020 – Oct 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test/telemetry: fix socket resource leak

If an error occurred when reading from the socket, the function returned without closing the socket. This is now fixed to avoid the resource leak of the sock variable going out of scope.

Fixes bd78cf693ebd ("test/telemetry: add unit tests for data to JSON")

Coverity issue: 363043

---
 app/test/test_telemetry_data.c | 1 +
 1 file changed, 1 insertion(+)
app/test/test_telemetry_data.c +1 -0
index 7a31e68a78..f3807a7255 100644
@@ -327,6 +327,7 @@ connect_to_socket(void)
 	if (bytes < 0) {
 		printf("%s: Error with socket read - %s\n", __func__,
 				strerror(errno));
+		close(sock);
 		return -1;
 	}
 	buf[bytes] = '\0';
Signature · 1 line
2.22.0
Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Ciara Power

If an error occurred when reading from the socket, the function returned without closing the socket. This is now fixed to avoid the resource leak of the sock variable going out of scope.

Fixes bd78cf693ebd ("test/telemetry: add unit tests for data to JSON")

Coverity issue: 363043

---
  app/test/test_telemetry_data.c | 1 +
  1 file changed, 1 insertion(+)
app/test/test_telemetry_data.c +0 -0
index 7a31e68a78..f3807a7255 100644

app/test/test_telemetry_data.c connect_to_socket(void) · line 333

Quoted 7 lines
app/test/test_telemetry_data.c +1 -0
@@ -327,6 +327,7 @@ connect_to_socket(void)
  	if (bytes < 0) {
  		printf("%s: Error with socket read - %s\n", __func__,
  				strerror(errno));
+		close(sock);
  		return -1;
  	}
  	buf[bytes] = '\0';
#2 lore raw

15/10/2020 19:02, Kevin Laatz:

Quoted 11 lines · Ciara Power
Quoted 8 lines

If an error occurred when reading from the socket, the function returned without closing the socket. This is now fixed to avoid the resource leak of the sock variable going out of scope.

Fixes bd78cf693ebd ("test/telemetry: add unit tests for data to JSON")

Coverity issue: 363043

Applied, thanks