out_es: fix msgpack initialization
@@ -165,10 +165,6 @@ static char *es_format(void *data, size_t bytes, int *out_size,
ctx->index, ctx->type);
off = 0;
- /* Create temporal msgpack buffer */
- msgpack_sbuffer_init(&tmp_sbuf);
- msgpack_packer_init(&tmp_pck, &tmp_sbuf, msgpack_sbuffer_write);
-
msgpack_unpacked_destroy(&result);
msgpack_unpacked_init(&result);
while (msgpack_unpack_next(&result, data, bytes, &off)) {
@@ -186,6 +182,10 @@ static char *es_format(void *data, size_t bytes, int *out_size,
map = root.via.array.ptr[1];
map_size = map.via.map.size;
+ /* Create temporal msgpack buffer */
+ msgpack_sbuffer_init(&tmp_sbuf);
+ msgpack_packer_init(&tmp_pck, &tmp_sbuf, msgpack_sbuffer_write);
+
msgpack_pack_map(&tmp_pck, map_size + 1);
/* Append date k/v */
@@ -225,7 +225,6 @@ static char *es_format(void *data, size_t bytes, int *out_size,
return NULL;
}
}
-
msgpack_unpacked_destroy(&result);
*out_size = bulk->len;
