mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
json: fix memory leak on result messages (checked with json_option_raw_test.v
, compiled with -fsanitize=address,pointer-compare,pointer-subtract
) (#23172)
This commit is contained in:
parent
c9542a2553
commit
fc8cd58782
2 changed files with 12 additions and 13 deletions
|
@ -252,6 +252,9 @@ fn json_parse(s string) &C.cJSON {
|
|||
@[markused]
|
||||
fn json_print(data &C.cJSON) string {
|
||||
s := C.cJSON_PrintUnformatted(data)
|
||||
if s == unsafe { nil } {
|
||||
return ''
|
||||
}
|
||||
r := unsafe { tos_clone(&u8(s)) }
|
||||
C.cJSON_free(s)
|
||||
return r
|
||||
|
@ -260,6 +263,9 @@ fn json_print(data &C.cJSON) string {
|
|||
@[markused]
|
||||
fn json_print_pretty(data &C.cJSON) string {
|
||||
s := C.cJSON_Print(data)
|
||||
if s == unsafe { nil } {
|
||||
return ''
|
||||
}
|
||||
r := unsafe { tos_clone(&u8(s)) }
|
||||
C.cJSON_free(s)
|
||||
return r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue