Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 161bfb1

Browse files
committed
DefaultElementLibrary was leaking its default builder
Fix the leak by managing the object life cycle with an unique_ptr. Signed-off-by: Kevin Rocard <kevin.rocard@intel.com>
1 parent 934ca72 commit 161bfb1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

parameter/DefaultElementLibrary.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
#include <map>
3636
#include <string>
37+
#include <memory>
38+
#include <utility>
3739

3840
/** Factory that creates an element given an xml element. If no matching builder is found, it uses
3941
* the default builder.
@@ -46,17 +48,16 @@ class CDefaultElementLibrary: public CElementLibrary
4648
{
4749
public:
4850

49-
CDefaultElementLibrary() : _defaultBuilder(NULL) {}
5051
virtual ~CDefaultElementLibrary() {}
5152

5253
/** Set the default builder used in fallback mechanism.
5354
* @see createElement() for more detail on this mechanism.
5455
*
5556
* @param[in] defaultBuilder if NULL default builder mechanism, else provided builder is used.
5657
*/
57-
void setDefaultBuilder(CDefaultElementBuilder* defaultBuilder)
58+
void setDefaultBuilder(std::unique_ptr<CDefaultElementBuilder> defaultBuilder)
5859
{
59-
_defaultBuilder = defaultBuilder;
60+
_defaultBuilder = std::move(defaultBuilder);
6061
}
6162

6263

@@ -73,7 +74,7 @@ class CDefaultElementLibrary: public CElementLibrary
7374
CElement* createElement(const CXmlElement& xmlElement) const;
7475

7576
private:
76-
CDefaultElementBuilder* _defaultBuilder;
77+
std::unique_ptr<CDefaultElementBuilder> _defaultBuilder;
7778
};
7879

7980
template<class CDefaultElementBuilder>

parameter/SystemClass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <assert.h>
3939
#include "PluginLocation.h"
4040
#include "Utility.h"
41+
#include "Memory.hpp"
4142

4243
#define base CConfigurableElement
4344

@@ -109,7 +110,7 @@ bool CSystemClass::loadSubsystems(string& strError,
109110
_pSubsystemLibrary->addElementBuilder("Virtual", new VirtualSubsystemBuilder(_logger));
110111
// Set virtual subsytem as builder fallback if required
111112
if (bVirtualSubsystemFallback) {
112-
_pSubsystemLibrary->setDefaultBuilder(new VirtualSubsystemBuilder(_logger));
113+
_pSubsystemLibrary->setDefaultBuilder(make_unique<VirtualSubsystemBuilder>(_logger));
113114
}
114115

115116
// Add subsystem defined in shared libraries

0 commit comments

Comments
 (0)