From 5175db27813c56298108f63a0f1e239b813d1e2d Mon Sep 17 00:00:00 2001 From: niansa Date: Thu, 1 Jun 2023 17:16:33 +0200 Subject: [PATCH] Fixed double-free in LLModel::Implementation destructor --- gpt4all-backend/llmodel.cpp | 11 ++++++++++- gpt4all-backend/llmodel.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gpt4all-backend/llmodel.cpp b/gpt4all-backend/llmodel.cpp index 02cdfa6f..5dfa1111 100644 --- a/gpt4all-backend/llmodel.cpp +++ b/gpt4all-backend/llmodel.cpp @@ -34,8 +34,17 @@ LLModel::Implementation::Implementation(Dlhandle &&dlhandle_) : dlhandle(new Dlh assert(construct_); } +LLModel::Implementation::Implementation(Implementation &&o) + : construct_(o.construct_) + , modelType(o.modelType) + , buildVariant(o.buildVariant) + , magicMatch(o.magicMatch) + , dlhandle(o.dlhandle) { + o.dlhandle = nullptr; +} + LLModel::Implementation::~Implementation() { - delete dlhandle; + if (dlhandle) delete dlhandle; } bool LLModel::Implementation::isImplementation(const Dlhandle &dl) { diff --git a/gpt4all-backend/llmodel.h b/gpt4all-backend/llmodel.h index 882a369c..f57a1e8a 100644 --- a/gpt4all-backend/llmodel.h +++ b/gpt4all-backend/llmodel.h @@ -17,6 +17,8 @@ public: public: Implementation(Dlhandle&&); + Implementation(const Implementation&) = delete; + Implementation(Implementation&&); ~Implementation(); static bool isImplementation(const Dlhandle&);