Skip to content

Commit ccc7bb7

Browse files
committed
fix memory leaks in minicpmv
1 parent a89f75e commit ccc7bb7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

examples/llava/clip.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,7 @@ static std::vector<std::vector<clip_image_u8 *>> uhd_slice_image(const clip_imag
19271927
images[images.size()-1].push_back(patch);
19281928
}
19291929
}
1930+
delete refine_image;
19301931
}
19311932
return images;
19321933
}
@@ -1965,6 +1966,16 @@ bool clip_image_preprocess(struct clip_ctx * ctx, const clip_image_u8 * img, cli
19651966
clip_image_f32_free(res);
19661967
}
19671968
}
1969+
for (size_t i = 0; i < imgs.size(); ++i) {
1970+
for (size_t j = 0; j < imgs[i].size(); ++j) {
1971+
if (imgs[i][j] != nullptr) {
1972+
imgs[i][j]->buf.clear();
1973+
delete imgs[i][j];
1974+
}
1975+
}
1976+
imgs[i].clear();
1977+
}
1978+
imgs.clear();
19681979
return true;
19691980
}
19701981

examples/llava/llava.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ static bool encode_image_with_clip(clip_ctx * ctx_clip, int n_threads, const cli
298298
load_image_size->height = img->ny;
299299
clip_add_load_image_size(ctx_clip, load_image_size);
300300
LOG_INF("%s: load_image_size %d %d\n", __func__, load_image_size->width, load_image_size->height);
301+
delete[] img_res_v.data;
302+
img_res_v.size = 0;
303+
img_res_v.data = nullptr;
301304
}
302305
else if (strcmp(mm_patch_merge_type, "spatial_unpad") != 0) {
303306
// flat / default llava-1.5 type embedding

0 commit comments

Comments
 (0)