From 25f0e297f941899a9a7964fb9269b9bd7597323c Mon Sep 17 00:00:00 2001
From: Dmitry Simonenko <pmwkaa@gmail.com>
Date: Wed, 20 Feb 2013 19:53:03 +0400
Subject: [PATCH] bugfix1124304: Memory leak when infinitely calling
 index:count() https://bugs.launchpad.net/tarantool/+bug/1124304

---
 src/box/box_lua.m | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/box/box_lua.m b/src/box/box_lua.m
index c4f87b36fb..312a1574ee 100644
--- a/src/box/box_lua.m
+++ b/src/box/box_lua.m
@@ -848,6 +848,7 @@ lbox_index_count(struct lua_State *L)
 	if (argc == 0)
 		luaL_error(L, "index.count(): one or more arguments expected");
 	/* preparing single or multi-part key */
+	size_t allocated_size = palloc_allocated(fiber->gc_pool);
 	void *key;
 	int key_part_count;
 	if (argc == 1 && lua_type(L, 2) == LUA_TUSERDATA) {
@@ -879,6 +880,9 @@ lbox_index_count(struct lua_State *L)
 			continue;
 		count++;
 	}
+	/* truncate memory used by key */
+	ptruncate(fiber->gc_pool, allocated_size);
+
 	/* returning subtree size */
 	lua_pushnumber(L, count);
 	return 1;
-- 
GitLab