Skip to content

Commit

Permalink
filter_nest: Replace malloc/free inside loop
Browse files Browse the repository at this point in the history
Signed-off-by: Michiel Kalkman <mkalkman@shelde.com>
  • Loading branch information
Michiel Kalkman committed May 5, 2018
1 parent ba24b22 commit f14545d
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions plugins/filter_nest/nest.c
Expand Up @@ -278,20 +278,16 @@ static inline void pack_map(msgpack_packer * packer, msgpack_object * map,
struct filter_nest_ctx *ctx)
{
int i;
int size;
char *buf;

msgpack_object *key;

for (i = 0; i < map->via.map.size; i++) {
key = &map->via.map.ptr[i].key;

if (ctx->use_prefix) {
size = ctx->prefix_with_len + key->via.str.size;
buf = flb_malloc(size + 1);
snprintf(buf, size + 1, "%s%s", ctx->prefix_with, key->via.str.ptr);
helper_pack_string(packer, buf, size);
flb_free(buf);
msgpack_pack_str(packer, ctx->prefix_with_len + key->via.str.size);
msgpack_pack_str_body(packer, ctx->prefix_with, ctx->prefix_with_len);
msgpack_pack_str_body(packer, key->via.str.ptr, key->via.str.size);
}
else {
msgpack_pack_object(packer, *key);
Expand Down

0 comments on commit f14545d

Please sign in to comment.