From c398dc6c073857cc128d8b70d7b531d16d418a4a Mon Sep 17 00:00:00 2001 From: apocelipes Date: Fri, 1 Dec 2023 15:54:46 +0900 Subject: [PATCH] fix(Cursor): fix a memory leak detected by valgrind --- src/modules/cursor/cursor.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/modules/cursor/cursor.c b/src/modules/cursor/cursor.c index e9d03f6e6..f3d151765 100644 --- a/src/modules/cursor/cursor.c +++ b/src/modules/cursor/cursor.c @@ -96,13 +96,14 @@ void ffGenerateCursorJsonResult(FF_MAYBE_UNUSED FFCursorOptions* options, yyjson if (result.error.length) { - yyjson_mut_obj_add_str(doc, module, "error", result.error.chars); - return; + yyjson_mut_obj_add_strbuf(doc, module, "error", &result.error); + } + else + { + yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); + yyjson_mut_obj_add_strbuf(doc, obj, "theme", &result.theme); + yyjson_mut_obj_add_strbuf(doc, obj, "size", &result.size); } - - yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); - yyjson_mut_obj_add_strbuf(doc, obj, "theme", &result.theme); - yyjson_mut_obj_add_strbuf(doc, obj, "size", &result.size); ffStrbufDestroy(&result.error); ffStrbufDestroy(&result.theme);