pack: on exception, release unpacked result
@@ -706,6 +706,7 @@ flb_sds_t flb_msgpack_raw_to_json_sds(const void *in_buf, size_t in_size)
ret = msgpack_unpack_next(&result, in_buf, in_size, &off);
if (ret != MSGPACK_UNPACK_SUCCESS) {
flb_sds_destroy(out_buf);
+ msgpack_unpacked_destroy(&result);
return NULL;
}
@@ -930,8 +931,9 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
/* Encode current record into JSON in a temporary variable */
out_js = flb_msgpack_raw_to_json_sds(tmp_sbuf.data, tmp_sbuf.size);
if (!out_js) {
- msgpack_sbuffer_destroy(&tmp_sbuf);
flb_sds_destroy(out_buf);
+ msgpack_sbuffer_destroy(&tmp_sbuf);
+ msgpack_unpacked_destroy(&result);
return NULL;
}
@@ -941,9 +943,10 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
*/
out_tmp = flb_sds_cat(out_buf, out_js, flb_sds_len(out_js));
if (!out_tmp) {
- msgpack_sbuffer_destroy(&tmp_sbuf);
flb_sds_destroy(out_js);
flb_sds_destroy(out_buf);
+ msgpack_sbuffer_destroy(&tmp_sbuf);
+ msgpack_unpacked_destroy(&result);
return NULL;
}
@@ -959,8 +962,9 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
if (json_format == FLB_PACK_JSON_FORMAT_LINES) {
out_tmp = flb_sds_cat(out_buf, "\n", 1);
if (!out_tmp) {
- msgpack_sbuffer_destroy(&tmp_sbuf);
flb_sds_destroy(out_buf);
+ msgpack_sbuffer_destroy(&tmp_sbuf);
+ msgpack_unpacked_destroy(&result);
return NULL;
}
if (out_tmp != out_buf) {
@@ -1074,7 +1078,9 @@ int flb_msgpack_expand_map(char *map_data, size_t map_size,
}
msgpack_unpacked_init(&result);
- if ( (i=msgpack_unpack_next(&result, map_data, map_size, &off)) != MSGPACK_UNPACK_SUCCESS ){
+ if ((i=msgpack_unpack_next(&result, map_data, map_size, &off)) !=
+ MSGPACK_UNPACK_SUCCESS ) {
+ msgpack_unpacked_destroy(&result);
return -1;
}
if (result.data.type != MSGPACK_OBJECT_MAP) {
