From c87c12168a0c0ea122041852c9fcbb9ea8bf73bf Mon Sep 17 00:00:00 2001 From: ochafik Date: Sat, 28 Sep 2024 23:44:28 +0100 Subject: [PATCH] `tool-call`: fix memory leak in test --- tests/test-tool-call.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-tool-call.cpp b/tests/test-tool-call.cpp index 85f4decf8..ad34faaa9 100644 --- a/tests/test-tool-call.cpp +++ b/tests/test-tool-call.cpp @@ -35,8 +35,8 @@ static std::string read_file(const std::string &path) { return out; } -static llama_grammar * build_grammar(const std::string & grammar_str) { - return llama_grammar_init_impl(nullptr, grammar_str.c_str(), "root"); +static std::unique_ptr build_grammar(const std::string & grammar_str) { + return std::unique_ptr(llama_grammar_init_impl(nullptr, grammar_str.c_str(), "root")); } // TODO: extract to common helper (copied from test-grammar-integration.cpp) @@ -292,7 +292,7 @@ static void test_template(const std::string & template_file, const char * bos_to {"content", ""}, {"tool_calls", tool_calls} }, tools); - if (!match_string(content_less_delta, grammar)) { + if (!match_string(content_less_delta, grammar.get())) { throw std::runtime_error("Failed to match content-less delta against grammar:\n\nContent-less delta: " + content_less_delta + "\n\nGrammar: " + handler.grammar); } }