From 7bfd83ce05dc0fe61e964e4db8bf007fcd8597ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=A4=C3=9Fler?= Date: Sat, 14 Dec 2024 22:43:58 +0100 Subject: [PATCH] fix memory leak failure --- tests/test-gguf.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test-gguf.cpp b/tests/test-gguf.cpp index 7ee3c04e6da92..a4434bcafade1 100644 --- a/tests/test-gguf.cpp +++ b/tests/test-gguf.cpp @@ -752,7 +752,10 @@ static std::pair 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 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 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);