From 797a5d5c015077a363225d7deecef9e8981cf144 Mon Sep 17 00:00:00 2001 From: syaojun Date: Mon, 30 Mar 2026 23:09:09 +0800 Subject: [PATCH 1/3] fix: avoid using C-style pointers to prevent potential memory leaks Signed-off-by: syaojun --- cpp/src/graphar/status.h | 43 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/cpp/src/graphar/status.h b/cpp/src/graphar/status.h index 1ef388f59..ba45910a7 100644 --- a/cpp/src/graphar/status.h +++ b/cpp/src/graphar/status.h @@ -19,6 +19,7 @@ #pragma once +#include #include #include #include @@ -131,33 +132,38 @@ class Status { /** Create a success status. */ Status() noexcept : state_(nullptr) {} /** Destructor. */ - ~Status() noexcept { - if (state_ != nullptr) { - deleteState(); - } - } + ~Status() noexcept = default; /** * @brief Constructs a status with the specified error code and message. * @param code The error code of the status. * @param msg The error message of the status. */ Status(StatusCode code, std::string msg) { - state_ = new State; + state_ = std::make_unique(); state_->code = code; state_->msg = std::move(msg); } /** Copy the specified status. */ - Status(const Status& s) - : state_((s.state_ == nullptr) ? nullptr : new State(*s.state_)) {} - /** Move the specified status. */ - Status(Status&& s) noexcept : state_(s.state_) { s.state_ = nullptr; } - /** Move assignment operator. */ - Status& operator=(Status&& s) noexcept { - delete state_; - state_ = s.state_; - s.state_ = nullptr; + Status(const Status& s) { + if (s.state_) { + state_ = std::make_unique(*s.state_); + } + } + /** Copy assignment operator. */ + Status& operator=(const Status& s) { + if (this != &s) { + if (s.state_) { + state_ = std::make_unique(*s.state_); + } else { + state_.reset(); + } + } return *this; } + /** Move the specified status. */ + Status(Status&& s) noexcept = default; + /** Move assignment operator. */ + Status& operator=(Status&& s) noexcept = default; /** Returns a success status. */ static Status OK() { return {}; } @@ -262,16 +268,11 @@ class Status { } private: - void deleteState() { - delete state_; - state_ = nullptr; - } - struct State { StatusCode code; std::string msg; }; - State* state_; + std::unique_ptr state_; }; } // namespace graphar From d74de26c7caab88cfc539002ae1da93e218fef83 Mon Sep 17 00:00:00 2001 From: syaojun Date: Tue, 7 Apr 2026 20:05:34 +0800 Subject: [PATCH 2/3] fix: enable comparison success Signed-off-by: syaojun --- cpp/src/graphar/status.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/graphar/status.h b/cpp/src/graphar/status.h index ba45910a7..05b895ccb 100644 --- a/cpp/src/graphar/status.h +++ b/cpp/src/graphar/status.h @@ -233,7 +233,7 @@ class Status { } /** Return true iff the status indicates success. */ - constexpr bool ok() const { return (state_ == nullptr); } + constexpr bool ok() const { return (state_.get() == nullptr); } /** Return true iff the status indicates a key lookup error. */ constexpr bool IsKeyError() const { return code() == StatusCode::kKeyError; } From 3a25e8f83e038a1e24ef899f43ff19260b1e16c6 Mon Sep 17 00:00:00 2001 From: syaojun Date: Tue, 7 Apr 2026 20:14:52 +0800 Subject: [PATCH 3/3] fix: remove all constexpr Signed-off-by: syaojun --- cpp/src/graphar/status.h | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/cpp/src/graphar/status.h b/cpp/src/graphar/status.h index 05b895ccb..e4414d4ac 100644 --- a/cpp/src/graphar/status.h +++ b/cpp/src/graphar/status.h @@ -233,33 +233,23 @@ class Status { } /** Return true iff the status indicates success. */ - constexpr bool ok() const { return (state_.get() == nullptr); } + bool ok() const { return (state_.get() == nullptr); } /** Return true iff the status indicates a key lookup error. */ - constexpr bool IsKeyError() const { return code() == StatusCode::kKeyError; } + bool IsKeyError() const { return code() == StatusCode::kKeyError; } /** Return true iff the status indicates a type match error. */ - constexpr bool IsTypeError() const { - return code() == StatusCode::kTypeError; - } + bool IsTypeError() const { return code() == StatusCode::kTypeError; } /** Return true iff the status indicates invalid data. */ - constexpr bool IsInvalid() const { return code() == StatusCode::kInvalid; } + bool IsInvalid() const { return code() == StatusCode::kInvalid; } /** Return true iff the status indicates an index out of bounds. */ - constexpr bool IsIndexError() const { - return code() == StatusCode::kIndexError; - } + bool IsIndexError() const { return code() == StatusCode::kIndexError; } /** Return true iff the status indicates an yaml parse related failure. */ - constexpr bool IsYamlError() const { - return code() == StatusCode::kYamlError; - } + bool IsYamlError() const { return code() == StatusCode::kYamlError; } /** Return true iff the status indicates an arrow-related failure. */ - constexpr bool IsArrowError() const { - return code() == StatusCode::kArrowError; - } + bool IsArrowError() const { return code() == StatusCode::kArrowError; } /** Return the StatusCode value attached to this status. */ - constexpr StatusCode code() const { - return ok() ? StatusCode::kOK : state_->code; - } + StatusCode code() const { return ok() ? StatusCode::kOK : state_->code; } /** Return the specific error message attached to this status. */ const std::string& message() const {