Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com, Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [PATCH v2 1/2] Do not mix box_key_def_delete and free to delete key_def
Date: Thu, 15 Mar 2018 15:19:15 +0300	[thread overview]
Message-ID: <87d5c968fc7e9b823f93a827e5188678fb960f5a.1521116161.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1521116161.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1521116161.git.v.shpilevoy@tarantool.org>

Use key_def_delete instead. It is more safe to use one
destructor everywhere for a case, if in a future key_def will not
be deleted by simple free().

Signed-off-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
---
 src/box/alter.cc                |  3 ++-
 src/box/key_def.cc              | 10 ++++++++--
 src/box/key_def.h               |  7 +++++++
 src/box/schema.cc               |  4 ++--
 src/box/vinyl.c                 |  4 ++--
 src/box/vy_index.c              |  8 ++++----
 test/unit/vy_iterators_helper.c |  2 +-
 test/unit/vy_mem.c              |  4 ++--
 test/unit/vy_point_lookup.c     |  2 +-
 test/unit/vy_write_iterator.c   |  2 +-
 10 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 8455373b2..c89fe8814 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -328,7 +328,8 @@ index_def_new_from_tuple(struct tuple *tuple, struct space *space)
 	}
 	auto key_def_guard = make_scoped_guard([&] {
 		free(part_def);
-		free(key_def);
+		if (key_def != NULL)
+			key_def_delete(key_def);
 	});
 	if (is_166plus) {
 		/* 1.6.6+ */
diff --git a/src/box/key_def.cc b/src/box/key_def.cc
index 955349cf3..2f1574195 100644
--- a/src/box/key_def.cc
+++ b/src/box/key_def.cc
@@ -106,6 +106,12 @@ key_def_dup(const struct key_def *src)
 	return res;
 }
 
+void
+key_def_delete(struct key_def *def)
+{
+	free(def);
+}
+
 static void
 key_def_set_cmp(struct key_def *def)
 {
@@ -145,7 +151,7 @@ key_def_new_with_parts(struct key_part_def *parts, uint32_t part_count)
 			if (coll == NULL) {
 				diag_set(ClientError, ER_WRONG_INDEX_OPTIONS,
 					 i + 1, "collation was not found by ID");
-				free(def);
+				key_def_delete(def);
 				return NULL;
 			}
 		}
@@ -187,7 +193,7 @@ box_key_def_new(uint32_t *fields, uint32_t *types, uint32_t part_count)
 void
 box_key_def_delete(box_key_def_t *key_def)
 {
-	free(key_def);
+	key_def_delete(key_def);
 }
 
 int
diff --git a/src/box/key_def.h b/src/box/key_def.h
index 4726c38a2..fe9ee56f7 100644
--- a/src/box/key_def.h
+++ b/src/box/key_def.h
@@ -149,6 +149,13 @@ struct key_def {
 struct key_def *
 key_def_dup(const struct key_def *src);
 
+/**
+ * Delete @a key_def.
+ * @param def Key_def to delete.
+ */
+void
+key_def_delete(struct key_def *def);
+
 /** \cond public */
 
 typedef struct key_def box_key_def_t;
diff --git a/src/box/schema.cc b/src/box/schema.cc
index 2e8533b94..1b96f978c 100644
--- a/src/box/schema.cc
+++ b/src/box/schema.cc
@@ -278,7 +278,7 @@ schema_init()
 	struct key_def *key_def = key_def_new(1); /* part count */
 	if (key_def == NULL)
 		diag_raise();
-	auto key_def_guard = make_scoped_guard([&] { box_key_def_delete(key_def); });
+	auto key_def_guard = make_scoped_guard([&] { key_def_delete(key_def); });
 
 	key_def_set_part(key_def, 0 /* part no */, 0 /* field no */,
 			 FIELD_TYPE_STRING, false, NULL);
@@ -329,7 +329,7 @@ schema_init()
 	sc_space_new(BOX_CLUSTER_ID, "_cluster", key_def, &on_replace_cluster,
 		     NULL);
 
-	free(key_def);
+	key_def_delete(key_def);
 	key_def = key_def_new(2); /* part count */
 	if (key_def == NULL)
 		diag_raise();
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 3467281a7..225698eb0 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -3097,7 +3097,7 @@ vy_join_cb(const struct vy_log_record *record, void *arg)
 		ctx->space_id = record->space_id;
 		ctx->index_id = record->index_id;
 		if (ctx->key_def != NULL)
-			free(ctx->key_def);
+			key_def_delete(ctx->key_def);
 		ctx->key_def = key_def_new_with_parts(record->key_parts,
 						      record->key_part_count);
 		if (ctx->key_def == NULL)
@@ -3234,7 +3234,7 @@ vinyl_engine_join(struct engine *engine, struct vclock *vclock,
 
 	/* Cleanup. */
 	if (ctx->key_def != NULL)
-		free(ctx->key_def);
+		key_def_delete(ctx->key_def);
 	if (ctx->format != NULL)
 		tuple_format_unref(ctx->format);
 	if (ctx->upsert_format != NULL)
diff --git a/src/box/vy_index.c b/src/box/vy_index.c
index 68fccab52..d9160041b 100644
--- a/src/box/vy_index.c
+++ b/src/box/vy_index.c
@@ -257,9 +257,9 @@ fail_mem_format_with_colmask:
 fail_upsert_format:
 	tuple_format_unref(index->disk_format);
 fail_format:
-	free(cmp_def);
+	key_def_delete(cmp_def);
 fail_cmp_def:
-	free(key_def);
+	key_def_delete(key_def);
 fail_key_def:
 	free(index->tree);
 fail_tree:
@@ -308,8 +308,8 @@ vy_index_delete(struct vy_index *index)
 	tuple_format_unref(index->disk_format);
 	tuple_format_unref(index->mem_format_with_colmask);
 	tuple_format_unref(index->upsert_format);
-	free(index->cmp_def);
-	free(index->key_def);
+	key_def_delete(index->cmp_def);
+	key_def_delete(index->key_def);
 	histogram_delete(index->run_hist);
 	vy_index_stat_destroy(&index->stat);
 	vy_cache_destroy(&index->cache);
diff --git a/test/unit/vy_iterators_helper.c b/test/unit/vy_iterators_helper.c
index 0e41de4b1..9eab13d34 100644
--- a/test/unit/vy_iterators_helper.c
+++ b/test/unit/vy_iterators_helper.c
@@ -252,7 +252,7 @@ destroy_test_cache(struct vy_cache *cache, struct key_def *def,
 {
 	tuple_format_unref(format);
 	vy_cache_destroy(cache);
-	box_key_def_delete(def);
+	key_def_delete(def);
 }
 
 bool
diff --git a/test/unit/vy_mem.c b/test/unit/vy_mem.c
index 5d1608771..60fcf0849 100644
--- a/test/unit/vy_mem.c
+++ b/test/unit/vy_mem.c
@@ -56,7 +56,7 @@ test_basic(void)
 
 	/* Clean up */
 	vy_mem_delete(mem);
-	box_key_def_delete(key_def);
+	key_def_delete(key_def);
 
 	fiber_gc();
 	footer();
@@ -302,7 +302,7 @@ test_iterator_restore_after_insertion()
 
 	tuple_format_unref(format);
 	lsregion_destroy(&lsregion);
-	box_key_def_delete(key_def);
+	key_def_delete(key_def);
 
 	fiber_gc();
 
diff --git a/test/unit/vy_point_lookup.c b/test/unit/vy_point_lookup.c
index 52f4427e9..963329c9f 100644
--- a/test/unit/vy_point_lookup.c
+++ b/test/unit/vy_point_lookup.c
@@ -312,7 +312,7 @@ test_basic()
 	index_def_delete(index_def);
 	tuple_format_unref(format);
 	vy_cache_destroy(&cache);
-	box_key_def_delete(key_def);
+	key_def_delete(key_def);
 	vy_cache_env_destroy(&cache_env);
 	vy_run_env_destroy(&run_env);
 	vy_index_env_destroy(&index_env);
diff --git a/test/unit/vy_write_iterator.c b/test/unit/vy_write_iterator.c
index 9058298cb..bf8ef39e8 100644
--- a/test/unit/vy_write_iterator.c
+++ b/test/unit/vy_write_iterator.c
@@ -501,7 +501,7 @@ test_basic(void)
 				       expected, expected_count,
 				       vlsns, vlsns_count, true, false);
 }
-	box_key_def_delete(key_def);
+	key_def_delete(key_def);
 	fiber_gc();
 	footer();
 	check_plan();
-- 
2.14.3 (Apple Git-98)

  reply	other threads:[~2018-03-15 12:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-15 12:19 [PATCH v2 0/2] vinyl: in a task use copy of index key defs to protect from alter Vladislav Shpilevoy
2018-03-15 12:19 ` Vladislav Shpilevoy [this message]
2018-03-15 12:19 ` [PATCH v2 2/2] " Vladislav Shpilevoy
2018-03-16 13:00 ` [PATCH v2 0/2] " Vladimir Davydov
2018-03-20 13:13 ` Vladimir Davydov
2018-03-20 13:18   ` v.shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d5c968fc7e9b823f93a827e5188678fb960f5a.1521116161.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v2 1/2] Do not mix box_key_def_delete and free to delete key_def' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox