Make the Server keep a shared_ptr instead of a raw Library pointer.

We want to be sure that `Library` actually exists when we use it.
While it is not a silver bullet (user can still create a shared_ptr on
a raw pointer), making the `Server` keep `shared_ptr` on the library
help us a lot here.
This commit is contained in:
Matthieu Gautier
2023-09-25 16:15:32 +02:00
parent efcbf6ef1e
commit a5557eeb25
6 changed files with 14 additions and 14 deletions

View File

@@ -36,7 +36,7 @@ namespace kiwix
*
* @param library The library to serve.
*/
Server(Library* library, NameMapper* nameMapper=nullptr);
Server(std::shared_ptr<Library> library, NameMapper* nameMapper=nullptr);
virtual ~Server();
@@ -66,7 +66,7 @@ namespace kiwix
std::string getAddress();
protected:
Library* mp_library;
std::shared_ptr<Library> mp_library;
NameMapper* mp_nameMapper;
std::string m_root = "";
std::string m_addr = "";