Skip to content

Commit

Permalink
fix double free
Browse files Browse the repository at this point in the history
Signed-off-by: sunby <[email protected]>
  • Loading branch information
sunby committed Dec 11, 2024
1 parent c64714e commit d174ec2
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 92 deletions.
10 changes: 7 additions & 3 deletions internal/core/thirdparty/tantivy/rust-array.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <iostream>
#include <memory>
#include <sstream>

#include "tantivy-binding.h"
Expand Down Expand Up @@ -72,7 +73,8 @@ struct RustResultWrapper {
NO_COPY_OR_ASSIGN(RustResultWrapper);

RustResultWrapper() = default;
explicit RustResultWrapper(RustResult result) : result_(result) {
explicit RustResultWrapper(RustResult result)
: result_(std::make_unique<RustResult>(result)) {
}

RustResultWrapper(RustResultWrapper&& other) noexcept {
Expand All @@ -93,12 +95,14 @@ struct RustResultWrapper {
free();
}

RustResult result_;
std::unique_ptr<RustResult> result_;

private:
void
free() {
free_rust_result(result_);
if (result_) {
free_rust_result(*result_.release());
}
}
};

Expand Down
Loading

0 comments on commit d174ec2

Please sign in to comment.