dovecot-2.2: cassandra: Minor code cleanup to make sure we don't...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 11 12:31:15 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/34943b67e01f
changeset: 18840:34943b67e01f
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 11 15:28:46 2015 +0300
description:
cassandra: Minor code cleanup to make sure we don't try to access freed transaction memory.

diffstat:

 src/lib-sql/driver-cassandra.c |  17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diffs (70 lines):

diff -r 247c6ae2eae4 -r 34943b67e01f src/lib-sql/driver-cassandra.c
--- a/src/lib-sql/driver-cassandra.c	Thu Jun 11 15:28:05 2015 +0300
+++ b/src/lib-sql/driver-cassandra.c	Thu Jun 11 15:28:46 2015 +0300
@@ -769,8 +769,11 @@
 }
 
 static void
-driver_cassandra_transaction_unref(struct cassandra_transaction_context *ctx)
+driver_cassandra_transaction_unref(struct cassandra_transaction_context **_ctx)
 {
+	struct cassandra_transaction_context *ctx = *_ctx;
+
+	*_ctx = NULL;
 	i_assert(ctx->refcount > 0);
 	if (--ctx->refcount > 0)
 		return;
@@ -790,7 +793,7 @@
 	} else {
 		ctx->begin_succeeded = TRUE;
 	}
-	driver_cassandra_transaction_unref(ctx);
+	driver_cassandra_transaction_unref(&ctx);
 }
 
 static void
@@ -801,7 +804,7 @@
 		ctx->callback(sql_result_get_error(result), ctx->context);
 	else
 		ctx->callback(NULL, ctx->context);
-	driver_cassandra_transaction_unref(ctx);
+	driver_cassandra_transaction_unref(&ctx);
 }
 
 static void
@@ -815,7 +818,7 @@
 		ctx->failed = TRUE;
 		ctx->error = sql_result_get_error(result);
 	}
-	driver_cassandra_transaction_unref(ctx);
+	driver_cassandra_transaction_unref(&ctx);
 }
 
 static void
@@ -830,7 +833,7 @@
 
 	if (ctx->failed || _ctx->head == NULL) {
 		callback(ctx->failed ? ctx->error : NULL, context);
-		driver_cassandra_transaction_unref(ctx);
+		driver_cassandra_transaction_unref(&ctx);
 	} else if (_ctx->head->next == NULL) {
 		/* just a single query, send it */
 		sql_query(_ctx->db, _ctx->head->query,
@@ -942,7 +945,7 @@
 
 	i_assert(ctx->refcount == 1);
 	i_assert((*error_r != NULL) == ctx->failed);
-	driver_cassandra_transaction_unref(ctx);
+	driver_cassandra_transaction_unref(&ctx);
 	return *error_r == NULL ? 0 : -1;
 }
 
@@ -953,7 +956,7 @@
 		(struct cassandra_transaction_context *)_ctx;
 
 	i_assert(ctx->refcount == 1);
-	driver_cassandra_transaction_unref(ctx);
+	driver_cassandra_transaction_unref(&ctx);
 }
 
 static void


More information about the dovecot-cvs mailing list