From 2abea46a87743f076759843136d7e3af3015b670 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 10 Nov 2019 22:05:52 +0700 Subject: [PATCH] #1273 Fixed crash when use "GET /2/backends" API endpoint with disabled CUDA. --- src/backend/cuda/CudaBackend.cpp | 24 +++++++++++++----------- src/backend/cuda/wrappers/CudaLib.h | 5 +++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/backend/cuda/CudaBackend.cpp b/src/backend/cuda/CudaBackend.cpp index feb1dd93..812ee270 100644 --- a/src/backend/cuda/CudaBackend.cpp +++ b/src/backend/cuda/CudaBackend.cpp @@ -474,19 +474,21 @@ rapidjson::Value xmrig::CudaBackend::toJSON(rapidjson::Document &doc) const out.AddMember("algo", d_ptr->algo.toJSON(), allocator); out.AddMember("profile", profileName().toJSON(), allocator); - Value versions(kObjectType); - versions.AddMember("cuda-runtime", Value(CudaLib::version(d_ptr->runtimeVersion).c_str(), allocator), allocator); - versions.AddMember("cuda-driver", Value(CudaLib::version(d_ptr->driverVersion).c_str(), allocator), allocator); - versions.AddMember("plugin", String(CudaLib::pluginVersion()).toJSON(doc), allocator); + if (CudaLib::isReady()) { + Value versions(kObjectType); + versions.AddMember("cuda-runtime", Value(CudaLib::version(d_ptr->runtimeVersion).c_str(), allocator), allocator); + versions.AddMember("cuda-driver", Value(CudaLib::version(d_ptr->driverVersion).c_str(), allocator), allocator); + versions.AddMember("plugin", String(CudaLib::pluginVersion()).toJSON(doc), allocator); -# ifdef XMRIG_FEATURE_NVML - if (NvmlLib::isReady()) { - versions.AddMember("nvml", StringRef(NvmlLib::version()), allocator); - versions.AddMember("driver", StringRef(NvmlLib::driverVersion()), allocator); +# ifdef XMRIG_FEATURE_NVML + if (NvmlLib::isReady()) { + versions.AddMember("nvml", StringRef(NvmlLib::version()), allocator); + versions.AddMember("driver", StringRef(NvmlLib::driverVersion()), allocator); + } +# endif + + out.AddMember("versions", versions, allocator); } -# endif - - out.AddMember("versions", versions, allocator); if (d_ptr->threads.empty() || !hashrate()) { return out; diff --git a/src/backend/cuda/wrappers/CudaLib.h b/src/backend/cuda/wrappers/CudaLib.h index 10ef24fe..f18ed350 100644 --- a/src/backend/cuda/wrappers/CudaLib.h +++ b/src/backend/cuda/wrappers/CudaLib.h @@ -69,8 +69,9 @@ public: static const char *lastError() noexcept; static void close(); - static inline bool isInitialized() { return m_initialized; } - static inline const String &loader() { return m_loader; } + static inline bool isInitialized() { return m_initialized; } + static inline bool isReady() noexcept { return m_ready; } + static inline const String &loader() { return m_loader; } static bool cnHash(nvid_ctx *ctx, uint32_t startNonce, uint64_t height, uint64_t target, uint32_t *rescount, uint32_t *resnonce); static bool deviceInit(nvid_ctx *ctx) noexcept;