From: RealOrko Date: Wed, 8 Apr 2026 15:40:15 +0000 (+0100) Subject: fix: free ctx_copy in ggml_opt_free to plug per-training-session leak (#21592) X-Git-Tag: upstream/0.0.10438~1719 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=2dcb7f74edde532831c5ee9a9b6c403f2b68854f;p=pkg%2Fggml%2Fsources%2Fllama.cpp fix: free ctx_copy in ggml_opt_free to plug per-training-session leak (#21592) * fix: free ctx_copy in ggml_opt_free to plug per-training-session leak ggml_opt_alloc populates opt_ctx->ctx_copy via a free+init pair every time the allocated graph shape changes. The last ctx_copy from the final ggml_opt_alloc call survives until ggml_opt_free is invoked, but ggml_opt_free was only freeing ctx_static and ctx_cpu, never ctx_copy. Each opt_ctx lifetime therefore leaks the final per-batch context — ~900 KB for a typical GNN training session in sindarin-pkg-tensor, surfaced via AddressSanitizer. ctx_copy is nullptr-initialized and ggml_free() handles NULL safely, so the new release is guard-free. * Update ggml/src/ggml-opt.cpp Co-authored-by: Johannes Gäßler --------- Co-authored-by: realorko Co-authored-by: Johannes Gäßler --- diff --git a/ggml/src/ggml-opt.cpp b/ggml/src/ggml-opt.cpp index e078ad14a..53903defa 100644 --- a/ggml/src/ggml-opt.cpp +++ b/ggml/src/ggml-opt.cpp @@ -589,6 +589,7 @@ void ggml_opt_free(ggml_opt_context_t opt_ctx) { ggml_backend_buffer_free(opt_ctx->buf_cpu); ggml_free(opt_ctx->ctx_static); ggml_free(opt_ctx->ctx_cpu); + ggml_free(opt_ctx->ctx_copy); delete opt_ctx; }