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 7bfd83c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/test-gguf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7bfd83c

Please sign in to comment.