]> www.infradead.org Git - users/griffoul/linux.git/commitdiff
selftests: net: fix memory leak in tls.c
authorCryolitia PukNgae <cryolitia@uniontech.com>
Tue, 19 Aug 2025 02:45:57 +0000 (10:45 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 21 Aug 2025 17:57:12 +0000 (10:57 -0700)
To free memory and close fd after use

Suggested-by: Jun Zhan <zhanjun@uniontech.com>
Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
Link: https://patch.msgid.link/20250819-memoryleak-v1-1-d4c70a861e62@uniontech.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/tls.c

index d8cfcf9bb82594ca078c998ce5849131bf46ade8..23cf6ff5fa49378bd7906334ff402aa61a205f29 100644 (file)
@@ -427,6 +427,8 @@ TEST_F(tls, sendfile)
        EXPECT_GE(filefd, 0);
        fstat(filefd, &st);
        EXPECT_GE(sendfile(self->fd, filefd, 0, st.st_size), 0);
+
+       close(filefd);
 }
 
 TEST_F(tls, send_then_sendfile)
@@ -448,6 +450,9 @@ TEST_F(tls, send_then_sendfile)
 
        EXPECT_GE(sendfile(self->fd, filefd, 0, st.st_size), 0);
        EXPECT_EQ(recv(self->cfd, buf, st.st_size, MSG_WAITALL), st.st_size);
+
+       free(buf);
+       close(filefd);
 }
 
 static void chunked_sendfile(struct __test_metadata *_metadata,