From 8b0a1cef4133b45916da32f29090b92042b7cbd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Guillemet?= Date: Fri, 19 Jan 2024 14:26:35 +0100 Subject: [PATCH] Fix double free when passing unique_ptr by value --- src/main/java/org/bytedeco/javacpp/tools/Generator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bytedeco/javacpp/tools/Generator.java b/src/main/java/org/bytedeco/javacpp/tools/Generator.java index 286d3d24..08211c90 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Generator.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Generator.java @@ -1408,7 +1408,7 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver out.println(" return (typename UNIQUE_PTR_NAMESPACE::remove_const::type*)ptr;"); out.println(" }"); out.println(" operator U&() const { return uniquePtr; }"); - out.println(" operator U&&() { return UNIQUE_PTR_NAMESPACE::move(uniquePtr); }"); + out.println(" operator U&&() { owner = NULL; return UNIQUE_PTR_NAMESPACE::move(uniquePtr); }"); out.println(" operator U*() { return &uniquePtr; }"); out.println(" T* ptr;"); out.println(" size_t size;"); @@ -1437,7 +1437,7 @@ boolean classes(boolean handleExceptions, boolean defineAdapters, boolean conver out.println(" return ptr;"); out.println(" }"); out.println(" operator const T*() { return ptr; }"); - out.println(" operator T&&() { return MOVE_NAMESPACE::move(movedPtr); }"); + out.println(" operator T&&() { owner = NULL; return MOVE_NAMESPACE::move(movedPtr); }"); out.println(" T* ptr;"); out.println(" size_t size;"); out.println(" void* owner;");