From 168d6ee84c5ef4b8db1242dccb9c51ffef04bb02 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Mon, 10 Mar 2025 16:46:47 +0100 Subject: [PATCH] MT#59962 XMLRPC2DI: properly free heap allocated objects For the `XMLRPC2DIServer` class as well as for the `XMLRPC2DI` one, heap allocated objects aren't properly managed by destruction time. Pointers have to be initialized as NULL, and point only when allocation was successfull. Then by a destruction time, check them and free. Change-Id: I1a31813db254cc4ab0f7ecc7b382fcb3635feee0 --- apps/xmlrpc2di/XMLRPC2DI.cpp | 5 +++-- apps/xmlrpc2di/XMLRPC2DI.h | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/xmlrpc2di/XMLRPC2DI.cpp b/apps/xmlrpc2di/XMLRPC2DI.cpp index 56e8d106..c8a35b73 100644 --- a/apps/xmlrpc2di/XMLRPC2DI.cpp +++ b/apps/xmlrpc2di/XMLRPC2DI.cpp @@ -66,7 +66,7 @@ XMLRPC2DI* XMLRPC2DI::instance() return _instance; } -XMLRPC2DI::XMLRPC2DI(const string& mod_name) +XMLRPC2DI::XMLRPC2DI(const string& mod_name) : AmDynInvokeFactory(mod_name) { } @@ -348,7 +348,8 @@ XMLRPC2DIServer::XMLRPC2DIServer(unsigned int port, getcpsavg_method(s), getcpsmax_method(s), getcpslimit_method(s), - setcpslimit_method(s) + setcpslimit_method(s), + s(NULL), di_method(NULL) { INFO("XMLRPC Server: enabled builtin method 'calls'\n"); INFO("XMLRPC Server: enabled builtin method 'get_loglevel'\n"); diff --git a/apps/xmlrpc2di/XMLRPC2DI.h b/apps/xmlrpc2di/XMLRPC2DI.h index b2126b42..9ac1f7fe 100644 --- a/apps/xmlrpc2di/XMLRPC2DI.h +++ b/apps/xmlrpc2di/XMLRPC2DI.h @@ -134,6 +134,15 @@ class XMLRPC2DIServer bool multithreaded = false, unsigned int threads = 5); + ~XMLRPC2DIServer() { + if (s) { + delete s; + } + if (di_method) { + delete di_method; + } + } + bool initialize(); void run(); @@ -188,7 +197,11 @@ class XMLRPC2DI public: XMLRPC2DI(const string& mod_name); - ~XMLRPC2DI() { } + ~XMLRPC2DI() { + if (server) { + delete server; + } + } int onLoad(); // DI factory