[PATCH] Fix smbtorture memory leaks

Andreas Schneider asn at samba.org
Wed May 16 10:14:11 UTC 2018


Hi,

attached are two patches to address memory leaks. Those have been found by RH 
coverity scans.


Please review and push if OK.

Thanks,


	Andreas

-- 
Andreas Schneider                   GPG-ID: CC014E3D
Samba Team                             asn at samba.org
www.samba.org
-------------- next part --------------
>From f72d6fd23c22ed9dd4075569ce2415650f5a566b Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Wed, 16 May 2018 11:44:00 +0200
Subject: [PATCH 1/2] s4:torture: Do not leak memory in libsmbclient test

Found by Coverity.

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/torture/libsmbclient/libsmbclient.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c
index 91579f4b1b7..855163bf9a2 100644
--- a/source4/torture/libsmbclient/libsmbclient.c
+++ b/source4/torture/libsmbclient/libsmbclient.c
@@ -326,17 +326,18 @@ static bool torture_libsmbclient_readdirplus(struct torture_context *tctx)
 	torture_comment(tctx, "Testing smbc_set" #option "\n");\
 	smbc_set ##option(ctx, val);\
 	torture_comment(tctx, "Testing smbc_get" #option "\n");\
-	torture_assert_int_equal(tctx, smbc_get ##option(ctx), val, "failed " #option);
+	torture_assert_int_equal_goto(tctx, smbc_get ##option(ctx), val, ok, done, "failed " #option);
 
 #define TEST_OPTION_STRING(option, val) \
 	torture_comment(tctx, "Testing smbc_set" #option "\n");\
 	smbc_set ##option(ctx, strdup(val));\
 	torture_comment(tctx, "Testing smbc_get" #option "\n");\
-	torture_assert_str_equal(tctx, smbc_get ##option(ctx), val, "failed " #option);
+	torture_assert_str_equal_goto(tctx, smbc_get ##option(ctx), val, ok, done, "failed " #option);
 
 bool torture_libsmbclient_configuration(struct torture_context *tctx)
 {
 	SMBCCTX *ctx;
+	bool ok = true;
 
 	ctx = smbc_new_context();
 	torture_assert(tctx, ctx, "failed to get new context");
@@ -348,14 +349,16 @@ bool torture_libsmbclient_configuration(struct torture_context *tctx)
 	TEST_OPTION_STRING(User, "torture_user");
 	TEST_OPTION_INT(Timeout, 12345);
 
+done:
 	smbc_free_context(ctx, 1);
 
-	return true;
+	return ok;
 }
 
 bool torture_libsmbclient_options(struct torture_context *tctx)
 {
 	SMBCCTX *ctx;
+	bool ok = true;
 
 	ctx = smbc_new_context();
 	torture_assert(tctx, ctx, "failed to get new context");
@@ -375,9 +378,10 @@ bool torture_libsmbclient_options(struct torture_context *tctx)
 	TEST_OPTION_INT(OptionNoAutoAnonymousLogin, true);
 	TEST_OPTION_INT(OptionUseCCache, true);
 
+done:
 	smbc_free_context(ctx, 1);
 
-	return true;
+	return ok;
 }
 
 NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
-- 
2.16.3


>From 84bb9f34beebedc3ce441833dac3f1a8c744b926 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Wed, 16 May 2018 11:46:22 +0200
Subject: [PATCH 2/2] s4:torture: Do not leak file descriptor in smb2 oplock
 test

Found by Coverity.

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 source4/torture/smb2/oplock.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/source4/torture/smb2/oplock.c b/source4/torture/smb2/oplock.c
index cb1b5edddfe..9561f078c1a 100644
--- a/source4/torture/smb2/oplock.c
+++ b/source4/torture/smb2/oplock.c
@@ -4873,17 +4873,20 @@ static int do_child_process(int pipefd, const char *name)
 
 	ret = fcntl(fd, F_SETSIG, RT_SIGNAL_LEASE);
 	if (ret == -1) {
+		close(fd);
 		return 3;
 	}
 
 	ret = fcntl(fd, F_SETLEASE, F_WRLCK);
 	if (ret == -1) {
+		close(fd);
 		return 4;
 	}
 
 	/* Tell the parent we're ready. */
 	ret = sys_write(pipefd, &c, 1);
 	if (ret != 1) {
+		close(fd);
 		return 5;
 	}
 
@@ -4893,14 +4896,17 @@ static int do_child_process(int pipefd, const char *name)
 	/* Wait for RT_SIGNAL_LEASE or SIGALRM. */
 	ret = sigsuspend(&empty_set);
 	if (ret != -1 || errno != EINTR) {
+		close(fd);
 		return 6;
 	}
 
 	if (got_alarm == 1) {
+		close(fd);
 		return 10;
 	}
 
 	if (got_break != 1) {
+		close(fd);
 		return 7;
 	}
 
@@ -4913,6 +4919,7 @@ static int do_child_process(int pipefd, const char *name)
 	/* Remove our lease. */
 	ret = fcntl(fd, F_SETLEASE, F_UNLCK);
 	if (ret == -1) {
+		close(fd);
 		return 8;
 	}
 
-- 
2.16.3



More information about the samba-technical mailing list