[PATCH] A few Coverity fixes

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Apr 21 06:50:55 MDT 2015


Hi!

Review&push appreciated!

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 9ba7169ffd651787d1b889bc9b5667950da2e4a1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 31 Mar 2015 09:34:54 +0200
Subject: [PATCH 1/3] lib: Fix a few CIDs for Resource Leak

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/util/tests/file.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/util/tests/file.c b/lib/util/tests/file.c
index 8508081..f349c21 100644
--- a/lib/util/tests/file.c
+++ b/lib/util/tests/file.c
@@ -66,6 +66,7 @@ static bool test_afdgets(struct torture_context *tctx)
 	int fd;
 	char *line;
 	TALLOC_CTX *mem_ctx = tctx;
+	bool ret = false;
 	
 	torture_assert(tctx, file_save(TEST_FILENAME, (const void *)TEST_DATA, 
 							 strlen(TEST_DATA)),
@@ -76,18 +77,22 @@ static bool test_afdgets(struct torture_context *tctx)
 	torture_assert(tctx, fd != -1, "opening file");
 
 	line = afdgets(fd, mem_ctx, 8);
-	torture_assert(tctx, strcmp(line, TEST_LINE1) == 0, "line 1 mismatch");
+	torture_assert_goto(tctx, strcmp(line, TEST_LINE1) == 0, ret, done,
+			    "line 1 mismatch");
 
 	line = afdgets(fd, mem_ctx, 8);
-	torture_assert(tctx, strcmp(line, TEST_LINE2) == 0, "line 2 mismatch");
+	torture_assert_goto(tctx, strcmp(line, TEST_LINE2) == 0, ret, done,
+			    "line 2 mismatch");
 
 	line = afdgets(fd, mem_ctx, 8);
-	torture_assert(tctx, strcmp(line, TEST_LINE3) == 0, "line 3 mismatch");
-
+	torture_assert_goto(tctx, strcmp(line, TEST_LINE3) == 0, ret, done,
+			    "line 3 mismatch");
+	ret = true;
+done:
 	close(fd);
 
 	unlink(TEST_FILENAME);
-	return true;
+	return ret;
 }
 
 struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx)
-- 
1.9.1


From 7dcadb2de4b6eacd46e4461e8fbbfa1dd4a0b1fc Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 31 Mar 2015 21:15:53 +0200
Subject: [PATCH 2/3] tevent: Fix CID 1035381 Unchecked return value

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/tevent/testsuite.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/tevent/testsuite.c b/lib/tevent/testsuite.c
index 34d13bb..e9d1ef4 100644
--- a/lib/tevent/testsuite.c
+++ b/lib/tevent/testsuite.c
@@ -121,6 +121,7 @@ static bool test_event_context(struct torture_context *test,
 #endif
 	int finished=0;
 	struct timeval t;
+	int ret;
 
 	ev_ctx = tevent_context_init_byname(test, backend);
 	if (ev_ctx == NULL) {
@@ -135,7 +136,8 @@ static bool test_event_context(struct torture_context *test,
 	fde_count = 0;
 
 	/* create a pipe */
-	pipe(fd);
+	ret = pipe(fd);
+	torture_assert_int_equal(test, ret, 0, "pipe failed");
 
 	fde_read = tevent_add_fd(ev_ctx, ev_ctx, fd[0], TEVENT_FD_READ,
 			    fde_handler_read, fd);
-- 
1.9.1


From 9a09337d5e056c6b6d6f978979ece4a8e988d4f5 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 31 Mar 2015 21:24:45 +0200
Subject: [PATCH 3/3] lib: Fix CID 1107218 Resource leak

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/popt_common.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
index 6f27bac..44f6aae 100644
--- a/source3/lib/popt_common.c
+++ b/source3/lib/popt_common.c
@@ -368,11 +368,8 @@ static void popt_common_credentials_callback(poptContext con,
 		}
 
 		if (getenv("USER")) {
-			char *puser = SMB_STRDUP(getenv("USER"));
-			if (!puser) {
-				exit(ENOMEM);
-			}
-			set_cmdline_auth_info_username(auth_info, puser);
+			set_cmdline_auth_info_username(auth_info,
+						       getenv("USER"));
 		}
 
 		if (getenv("PASSWD")) {
-- 
1.9.1



More information about the samba-technical mailing list