From 60d065473e6f1429a60ad62f989489f648304331 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 24 May 2019 10:32:21 +0300 Subject: [PATCH] MXS-2481 Handle sqlite3 oom error --- .../monitor/clustrixmon/clustrixmonitor.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/server/modules/monitor/clustrixmon/clustrixmonitor.cc b/server/modules/monitor/clustrixmon/clustrixmonitor.cc index 4964d97ac..7f67f5c23 100644 --- a/server/modules/monitor/clustrixmon/clustrixmonitor.cc +++ b/server/modules/monitor/clustrixmon/clustrixmonitor.cc @@ -189,7 +189,23 @@ ClustrixMonitor* ClustrixMonitor::create(const string& name, const string& modul sqlite3* pDb = open_or_create_db(path); - return new ClustrixMonitor(name, module, pDb); + ClustrixMonitor* pThis = nullptr; + + if (pDb) + { + // Even if the creation/opening of the sqlite3 database fails, we will still + // get a valid database handle. + pThis = new ClustrixMonitor(name, module, pDb); + } + else + { + // The handle will be null, *only* if the opening fails due to a memory + // allocation error. + MXS_ALERT("sqlite3 memory allocation failed, the Clustrix monitor " + "cannot continue."); + } + + return pThis; } bool ClustrixMonitor::configure(const MXS_CONFIG_PARAMETER* pParams)