From 4549cd3a5d3a10910b37d6c4b4b5eb36462754a7 Mon Sep 17 00:00:00 2001 From: inabao <37021995+inabao@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:46:35 +0800 Subject: [PATCH] fix the memory leak issue in VisitListPool allocation (#229) Signed-off-by: jinjiabao.jjb --- include/vsag/allocator.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/vsag/allocator.h b/include/vsag/allocator.h index 449184c8..4278fc17 100644 --- a/include/vsag/allocator.h +++ b/include/vsag/allocator.h @@ -40,7 +40,12 @@ class Allocator { T* New(Args&&... args) { void* p = Allocate(sizeof(T)); - return (T*)::new (p) T(std::forward(args)...); + try { + return (T*)::new (p) T(std::forward(args)...); + } catch (std::exception& e) { + Deallocate(p); + throw e; + } } template