test/telemetry: fix socket resource leak

Message ID 20201013155648.3471-1-ciara.power@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series test/telemetry: fix socket resource leak |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Power, Ciara Oct. 13, 2020, 3:56 p.m. UTC
  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

Signed-off-by: Ciara Power <ciara.power@intel.com>
---
 app/test/test_telemetry_data.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Kevin Laatz Oct. 15, 2020, 5:02 p.m. UTC | #1
On 13/10/2020 16:56, Ciara Power wrote:
> 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
>
> Signed-off-by: Ciara Power <ciara.power@intel.com>
> ---
>   app/test/test_telemetry_data.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
> index 7a31e68a78..f3807a7255 100644
> --- a/app/test/test_telemetry_data.c
> +++ b/app/test/test_telemetry_data.c
> @@ -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';


Acked-by: Kevin Laatz <kevin.laatz@intel.com>
  
Thomas Monjalon Oct. 19, 2020, 2:59 p.m. UTC | #2
15/10/2020 19:02, Kevin Laatz:
> On 13/10/2020 16:56, Ciara Power wrote:
> > 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
> >
> > Signed-off-by: Ciara Power <ciara.power@intel.com>
> 
> Acked-by: Kevin Laatz <kevin.laatz@intel.com>

Applied, thanks
  

Patch

diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
index 7a31e68a78..f3807a7255 100644
--- a/app/test/test_telemetry_data.c
+++ b/app/test/test_telemetry_data.c
@@ -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';