Skip to content

Commit

Permalink
fix memory leaks in minicpmv
Browse files Browse the repository at this point in the history
  • Loading branch information
tc-mb committed Oct 14, 2024
1 parent a89f75e commit ccc7bb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/llava/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
delete refine_image;
}
return images;
}
Expand Down Expand Up @@ -1965,6 +1966,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;
}

Expand Down
3 changes: 3 additions & 0 deletions examples/llava/llava.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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);
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
Expand Down

0 comments on commit ccc7bb7

Please sign in to comment.