fix memory leak failure

This commit is contained in:
Johannes Gäßler 2024-12-14 22:43:58 +01:00
parent fecf662ec1
commit 7bfd83ce05

View file

@ -752,7 +752,10 @@ static std::pair<int, int> test_handcrafted_file(const unsigned int seed) {
ntest++;
}
gguf_free(gguf_ctx);
if (gguf_ctx) {
ggml_free(ctx);
gguf_free(gguf_ctx);
}
fclose(file);
printf("\n");
}
@ -775,6 +778,10 @@ static struct random_gguf_context_result get_random_gguf_context(ggml_backend_t
const std::string key = "my_key_" + std::to_string(rng() % 1024);
const enum gguf_type type = gguf_type(rng() % GGUF_TYPE_COUNT);
if (type == GGUF_TYPE_STRING || type == GGUF_TYPE_ARRAY) {
continue; // FIXME memory leak
}
switch (type) {
case GGUF_TYPE_UINT8: gguf_set_val_u8 (gguf_ctx, key.c_str(), rng() % (1 << 7)); break;
case GGUF_TYPE_INT8: gguf_set_val_i8 (gguf_ctx, key.c_str(), rng() % (1 << 7) - (1 << 6)); break;
@ -1134,6 +1141,7 @@ static std::pair<int, int> test_roundtrip(ggml_backend_dev_t dev, const unsigned
gguf_free(gguf_ctx_0);
gguf_free(gguf_ctx_1);
gguf_buf_free(gbuf);
ggml_backend_free(backend);
GGML_ASSERT(fclose(file) == 0);
printf("\n");
@ -1226,6 +1234,7 @@ static std::pair<int, int> test_gguf_set_kv(ggml_backend_dev_t dev, const unsign
gguf_free(gguf_ctx_0);
gguf_free(gguf_ctx_1);
gguf_free(gguf_ctx_2);
ggml_backend_free(backend);
printf("\n");
return std::make_pair(npass, ntest);