CTDB: Small patch set fixing memory leak and other things for ctdb_tcp_read_cb

Swen Schillig swen at vnet.ibm.com
Tue Mar 13 09:09:39 UTC 2018


The attached file contains 3 small patches fixing a memory leak,
removes not require checks and is cleaning up the code for column
length, function call formatting and using the right logging macros.

Please review and push if OK.

Thanks in advance.

Cheers Swen.
-------------- next part --------------
From 538224d51870f6efe16b962e3c3793f7d918ff68 Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at vnet.ibm.com>
Date: Tue, 13 Mar 2018 09:22:45 +0100
Subject: [PATCH 1/3] ctdb: Remove double sanity checks from ctdb_tcp_read_cb

Within ctdb_tcp_read_cb the provided data is checked for sanity,
e.g. correct size and content. This is not required because it was
done already by the caller.

Signed-off-by: Swen Schillig <swen at vnet.ibm.com>
---
 ctdb/tcp/tcp_io.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/ctdb/tcp/tcp_io.c b/ctdb/tcp/tcp_io.c
index 5bb4b5bd1a7..93aaedc8f51 100644
--- a/ctdb/tcp/tcp_io.c
+++ b/ctdb/tcp/tcp_io.c
@@ -45,24 +45,12 @@ void ctdb_tcp_read_cb(uint8_t *data, size_t cnt, void *args)
 		goto failed;
 	}
 
-	if (cnt < sizeof(*hdr)) {
-		DEBUG(DEBUG_ALERT,(__location__ " Bad packet length %u\n", (unsigned)cnt));
-		goto failed;
-	}
-
 	if (cnt & (CTDB_TCP_ALIGNMENT-1)) {
 		DEBUG(DEBUG_ALERT,(__location__ " Length 0x%x not multiple of alignment\n", 
 			 (unsigned)cnt));
 		goto failed;
 	}
 
-
-	if (cnt != hdr->length) {
-		DEBUG(DEBUG_ALERT,(__location__ " Bad header length %u expected %u\n", 
-			 (unsigned)hdr->length, (unsigned)cnt));
-		goto failed;
-	}
-
 	if (hdr->ctdb_magic != CTDB_MAGIC) {
 		DEBUG(DEBUG_ALERT,(__location__ " Non CTDB packet 0x%x rejected\n", 
 			 hdr->ctdb_magic));
-- 
2.14.3


From 050299b728c711e0a8f24a6d74e8c11beec12d87 Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at vnet.ibm.com>
Date: Tue, 13 Mar 2018 09:32:07 +0100
Subject: [PATCH 2/3] ctdb: Minor cleanup of ctdb_tcp_read_cb

Minor code cleanup of ctdb_tcp_read_cb adjusting for column length,
function call alignment and logging macros.

Signed-off-by: Swen Schillig <swen at vnet.ibm.com>
---
 ctdb/tcp/tcp_io.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/ctdb/tcp/tcp_io.c b/ctdb/tcp/tcp_io.c
index 93aaedc8f51..98df18cd545 100644
--- a/ctdb/tcp/tcp_io.c
+++ b/ctdb/tcp/tcp_io.c
@@ -46,20 +46,17 @@ void ctdb_tcp_read_cb(uint8_t *data, size_t cnt, void *args)
 	}
 
 	if (cnt & (CTDB_TCP_ALIGNMENT-1)) {
-		DEBUG(DEBUG_ALERT,(__location__ " Length 0x%x not multiple of alignment\n", 
-			 (unsigned)cnt));
+		D_ERR("Length 0x%x not multiple of alignment\n", (unsigned)cnt);
 		goto failed;
 	}
 
 	if (hdr->ctdb_magic != CTDB_MAGIC) {
-		DEBUG(DEBUG_ALERT,(__location__ " Non CTDB packet 0x%x rejected\n", 
-			 hdr->ctdb_magic));
+		D_ERR("Non CTDB packet 0x%x rejected\n", hdr->ctdb_magic);
 		goto failed;
 	}
 
 	if (hdr->ctdb_version != CTDB_PROTOCOL) {
-		DEBUG(DEBUG_ALERT, (__location__ " Bad CTDB version 0x%x rejected\n", 
-			  hdr->ctdb_version));
+		D_ERR("Bad CTDB version 0x%x rejected\n", hdr->ctdb_version);
 		goto failed;
 	}
 
@@ -68,7 +65,7 @@ void ctdb_tcp_read_cb(uint8_t *data, size_t cnt, void *args)
 	return;
 
 failed:
-	talloc_free(in);
+	TALLOC_FREE(in);
 }
 
 /*
-- 
2.14.3


From cf77160e23626d2f5d01ddcb6aaab7fb1b8aac2e Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at vnet.ibm.com>
Date: Tue, 13 Mar 2018 09:34:52 +0100
Subject: [PATCH 3/3] ctdb: Fixing possible memory leak in ctdb_tcp_read_cb

In case of an error condition the further processing of the data is cancelled
and the callback returns. In such a scenario the data has to be free'd.

Signed-off-by: Swen Schillig <swen at vnet.ibm.com>
---
 ctdb/tcp/tcp_io.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ctdb/tcp/tcp_io.c b/ctdb/tcp/tcp_io.c
index 98df18cd545..a6886ca3863 100644
--- a/ctdb/tcp/tcp_io.c
+++ b/ctdb/tcp/tcp_io.c
@@ -66,6 +66,7 @@ void ctdb_tcp_read_cb(uint8_t *data, size_t cnt, void *args)
 
 failed:
 	TALLOC_FREE(in);
+	TALLOC_FREE(data);
 }
 
 /*
-- 
2.14.3



More information about the samba-technical mailing list