Skip to content

Commit

Permalink
fix memory leak failure
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesGaessler committed Dec 14, 2024
1 parent fecf662 commit 9e6cb87
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/test-gguf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ static std::pair<int, int> test_handcrafted_file(const unsigned int seed) {
ntest++;
}

ggml_free(ctx);
gguf_free(gguf_ctx);
fclose(file);
printf("\n");
Expand All @@ -775,6 +776,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;
Expand Down Expand Up @@ -1134,6 +1139,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");
Expand Down Expand Up @@ -1226,6 +1232,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);
Expand Down

0 comments on commit 9e6cb87

Please sign in to comment.