mirror of
https://github.com/emqx/neuron.git
synced 2026-10-18 21:50:42 +08:00
fix: json utils to free memory correctly
This commit is contained in:
@@ -41,7 +41,9 @@ int neu_json_encode_by_fn(void *param, neu_json_encode_fn fn, char **result)
|
||||
}
|
||||
}
|
||||
|
||||
return neu_json_encode(object, result);
|
||||
int ret = neu_json_encode(object, result);
|
||||
neu_json_decode_free(object);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int neu_json_encode_with_mqtt(void *param, neu_json_encode_fn fn,
|
||||
@@ -64,7 +66,9 @@ int neu_json_encode_with_mqtt(void *param, neu_json_encode_fn fn,
|
||||
}
|
||||
}
|
||||
|
||||
return neu_json_encode(object, result);
|
||||
int ret = neu_json_encode(object, result);
|
||||
neu_json_decode_free(object);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int neu_parse_param(const char *buf, char **err_param, int n,
|
||||
|
||||
+1
-3
@@ -344,7 +344,7 @@ void *neu_json_encode_new()
|
||||
|
||||
void neu_json_encode_free(void *json_object)
|
||||
{
|
||||
free(json_object);
|
||||
json_decref(json_object);
|
||||
}
|
||||
|
||||
int neu_json_encode_field(void *json_object, neu_json_elem_t *elem, int n)
|
||||
@@ -360,8 +360,6 @@ int neu_json_encode(void *json_object, char **str)
|
||||
{
|
||||
*str = json_dumps(json_object, JSON_REAL_PRECISION(16));
|
||||
|
||||
json_decref(json_object);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,6 +173,7 @@ TEST(JsonTest, EncodeField)
|
||||
EXPECT_STREQ(result, buf);
|
||||
|
||||
free(result);
|
||||
neu_json_decode_free(ob);
|
||||
}
|
||||
|
||||
TEST(JsonTest, EncodeArray)
|
||||
@@ -241,6 +242,7 @@ TEST(JsonTest, EncodeArray)
|
||||
EXPECT_STREQ(result, buf);
|
||||
|
||||
free(result);
|
||||
neu_json_decode_free(ob);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
||||
Reference in New Issue
Block a user