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:
Felipe Pena 2024-12-15 11:43:43 -03:00 committed by GitHub
parent c9542a2553
commit fc8cd58782
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 13 deletions

View file

@ -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