From 840748e3c37a8138472c6a30ae061914a77c4282 Mon Sep 17 00:00:00 2001 From: Damian Kalinowski Date: Wed, 17 May 2023 10:27:47 +0200 Subject: [PATCH] remove memory leak --- blingfiretools/blingfiretokdll/blingfiretokdll.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/blingfiretools/blingfiretokdll/blingfiretokdll.cpp b/blingfiretools/blingfiretokdll/blingfiretokdll.cpp index 241d227..5d04c99 100644 --- a/blingfiretools/blingfiretokdll/blingfiretokdll.cpp +++ b/blingfiretools/blingfiretokdll/blingfiretokdll.cpp @@ -15,6 +15,8 @@ #include "blingfiretokdll.h" +#include + /* This library provides easy interface to sentence and word-breaking functionality which can be used in C#, Python, Perl, etc. @@ -1055,8 +1057,8 @@ void* SetModelData(FAModelData * pNewModelData, const unsigned char * pImgBytes) extern "C" void* SetModel(const unsigned char * pImgBytes, int ModelByteCount) { - FAModelData * pNewModelData = new FAModelData(); - if (NULL == pNewModelData) { + std::unique_ptr pNewModelData(new FAModelData()); + if (NULL == pNewModelData.get()) { return 0; } @@ -1066,7 +1068,7 @@ void* SetModel(const unsigned char * pImgBytes, int ModelByteCount) } // return the initialized model handle - return SetModelData(pNewModelData, pImgBytes); + return SetModelData(pNewModelData.release(), pImgBytes); } @@ -1077,8 +1079,8 @@ void* SetModel(const unsigned char * pImgBytes, int ModelByteCount) extern "C" void* LoadModel(const char * pszLdbFileName) { - FAModelData * pNewModelData = new FAModelData(); - if (NULL == pNewModelData) { + std::unique_ptr pNewModelData(new FAModelData()); + if (NULL == pNewModelData.get()) { return 0; } @@ -1090,7 +1092,7 @@ void* LoadModel(const char * pszLdbFileName) } // return the initialized model handle - return SetModelData(pNewModelData, pImgBytes); + return SetModelData(pNewModelData.release(), pImgBytes); }