From c900ada5584505385204ee4c7e1e3510c52c227e Mon Sep 17 00:00:00 2001 From: caitianchi Date: Mon, 23 Sep 2024 01:47:16 +0800 Subject: [PATCH] fix memory leaks --- examples/llava/clip.cpp | 11 +++++++++++ examples/llava/llava.cpp | 3 +++ 2 files changed, 14 insertions(+) diff --git a/examples/llava/clip.cpp b/examples/llava/clip.cpp index 3851c3a6735d1..c3a1b622ddba7 100644 --- a/examples/llava/clip.cpp +++ b/examples/llava/clip.cpp @@ -1936,6 +1936,7 @@ static std::vector> uhd_slice_image(const clip_imag images[images.size()-1].push_back(patch); } } + delete refine_image; } return images; } @@ -1975,6 +1976,16 @@ bool clip_image_preprocess(struct clip_ctx * ctx, const clip_image_u8 * img, cli clip_image_f32_free(res); } } + for (size_t i = 0; i < imgs.size(); ++i){ + for (size_t j = 0; j < imgs[i].size(); ++j) { + if (imgs[i][j] != nullptr) { + imgs[i][j]->buf.clear(); + delete imgs[i][j]; + } + } + imgs[i].clear(); + } + imgs.clear(); return true; } else { diff --git a/examples/llava/llava.cpp b/examples/llava/llava.cpp index ff054bb42fd8c..a3af7bd027aa0 100644 --- a/examples/llava/llava.cpp +++ b/examples/llava/llava.cpp @@ -288,6 +288,9 @@ static bool encode_image_with_clip(clip_ctx * ctx_clip, int n_threads, const cli load_image_size->height = img->ny; clip_add_load_image_size(ctx_clip, load_image_size); LOG_TEE("%s: load_image_size %d %d\n", __func__, load_image_size->width, load_image_size->height); + delete[] img_res_v.data; + img_res_v.size = 0; + img_res_v.data = nullptr; } else if (strcmp(mm_patch_merge_type, "spatial_unpad") != 0) { // flat / default llava-1.5 type embedding