diff --git a/vlib/json/json_primitives.v b/vlib/json/json_primitives.v index aade8e54c2..f46cfea747 100644 --- a/vlib/json/json_primitives.v +++ b/vlib/json/json_primitives.v @@ -28,6 +28,8 @@ fn C.cJSON_PrintUnformatted(&C.cJSON) &char fn C.cJSON_Print(&C.cJSON) &char +fn C.cJSON_free(voidptr) + pub fn decode(typ voidptr, s string) ?voidptr { // compiler implementation return 0 @@ -215,12 +217,16 @@ fn json_parse(s string) &C.cJSON { // json_string := json_print(encode_User(user)) fn json_print(json &C.cJSON) string { s := C.cJSON_PrintUnformatted(json) - return unsafe { tos(&u8(s), C.strlen(&char(s))) } + r := unsafe { tos_clone(&u8(s)) } + C.cJSON_free(s) + return r } fn json_print_pretty(json &C.cJSON) string { s := C.cJSON_Print(json) - return unsafe { tos(&u8(s), C.strlen(&char(s))) } + r := unsafe { tos_clone(&u8(s)) } + C.cJSON_free(s) + return r } // / cjson wrappers