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 1/2] 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;"); From ac1b18fcbb4037e887b5e1320eb23cd13c4e1d32 Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Sat, 20 Jan 2024 08:58:13 +0900 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 071b30f7..74dd8098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Fix `MoveAdapter` and `UniquePtrAdapter` causing double free on function calls ([pull #738](https://github.com/bytedeco/javacpp/pull/738)) * Fix `Parser` handling of `template` specialization and their `friend` declarations ([pull #733](https://github.com/bytedeco/javacpp/pull/733)) * Improve `Parser` capabilities for `operator` and function templates ([pull #732](https://github.com/bytedeco/javacpp/pull/732)) * Fix `Parser` failing on nested initializer lists and on attributes found inside `enum` declarations