[lttng-dev] [PATCH lttng-tools] Fix: filter bytecode and string memory leak on error

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Tue Nov 11 16:34:30 EST 2014


Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
 src/bin/lttng-sessiond/main.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c
index 9542e65..50da40c 100644
--- a/src/bin/lttng-sessiond/main.c
+++ b/src/bin/lttng-sessiond/main.c
@@ -3217,12 +3217,14 @@ skip_domain:
 
 			if (bytecode_len > LTTNG_FILTER_MAX_LEN) {
 				ret = LTTNG_ERR_FILTER_INVAL;
+				free(filter_expression);
 				free(exclusion);
 				goto error;
 			}
 
 			bytecode = zmalloc(bytecode_len);
 			if (!bytecode) {
+				free(filter_expression);
 				free(exclusion);
 				ret = LTTNG_ERR_FILTER_NOMEM;
 				goto error;
@@ -3234,6 +3236,7 @@ skip_domain:
 			if (ret <= 0) {
 				DBG("Nothing recv() from client car len data... continuing");
 				*sock_error = 1;
+				free(filter_expression);
 				free(bytecode);
 				free(exclusion);
 				ret = LTTNG_ERR_FILTER_INVAL;
@@ -3241,6 +3244,7 @@ skip_domain:
 			}
 
 			if ((bytecode->len + sizeof(*bytecode)) != bytecode_len) {
+				free(filter_expression);
 				free(bytecode);
 				free(exclusion);
 				ret = LTTNG_ERR_FILTER_INVAL;
@@ -3253,6 +3257,12 @@ skip_domain:
 				&cmd_ctx->lsm->u.enable.event,
 				filter_expression, bytecode, exclusion,
 				kernel_poll_pipe[1]);
+		if (ret != LTTNG_OK) {
+			/* On error, we still have ownership. */
+			free(filter_expression);
+			free(bytecode);
+			free(exclusion);
+		}
 		break;
 	}
 	case LTTNG_LIST_TRACEPOINTS:
-- 
2.1.1




More information about the lttng-dev mailing list