From a88942019fdd3d8fc366999f7c178f3e1c18b2fe Mon Sep 17 00:00:00 2001 From: "zhaogang.0108" Date: Fri, 22 Dec 2023 08:53:40 +0000 Subject: bmcweb: Add nullptr check for weakptr When we call a null weakptr, it will cause a crash. Add nullptr check for weakptr can avoid this situation. Tested: bmcweb.service did not experience core-dump. Change-Id: I4490d68c70ea5d43681f4fb18b3859afb01ed70a Signed-off-by: Zhao Gang --- http/websocket.hpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'http') diff --git a/http/websocket.hpp b/http/websocket.hpp index 027ab24642..4f5b3c18a6 100644 --- a/http/websocket.hpp +++ b/http/websocket.hpp @@ -162,6 +162,11 @@ class ConnectionImpl : public Connection [weak(weak_from_this()), onDone{std::move(onDone)}]( const boost::beast::error_code& ec, size_t) { std::shared_ptr self = weak.lock(); + if (!self) + { + BMCWEB_LOG_ERROR("Connection went away"); + return; + } // Call the done handler regardless of whether we // errored, but before we close things out -- cgit v1.2.3