fix memory leaks in minicpmv

This commit is contained in:
caitianchi 2024-10-14 15:57:34 +08:00
parent a89f75e1b7
commit 93f85ea213
2 changed files with 14 additions and 0 deletions

View file

@ -1927,6 +1927,7 @@ static std::vector<std::vector<clip_image_u8 *>> uhd_slice_image(const clip_imag
images[images.size()-1].push_back(patch); images[images.size()-1].push_back(patch);
} }
} }
delete refine_image;
} }
return images; return images;
} }
@ -1965,6 +1966,16 @@ bool clip_image_preprocess(struct clip_ctx * ctx, const clip_image_u8 * img, cli
clip_image_f32_free(res); 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; return true;
} }

View file

@ -298,6 +298,9 @@ static bool encode_image_with_clip(clip_ctx * ctx_clip, int n_threads, const cli
load_image_size->height = img->ny; load_image_size->height = img->ny;
clip_add_load_image_size(ctx_clip, load_image_size); clip_add_load_image_size(ctx_clip, load_image_size);
LOG_INF("%s: load_image_size %d %d\n", __func__, load_image_size->width, load_image_size->height); LOG_INF("%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) { else if (strcmp(mm_patch_merge_type, "spatial_unpad") != 0) {
// flat / default llava-1.5 type embedding // flat / default llava-1.5 type embedding