yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

Merge pull request #440 from yuriks/lifetime-fix

Fix double-free in Service manager during shutdown
This commit is contained in:
bunnei 2015-01-07 14:57:36 -05:00
commit 43ba29f3bf
2 changed files with 4 additions and 25 deletions

View File

@ -46,36 +46,22 @@ Manager* g_manager = nullptr; ///< Service manager
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Service Manager class // Service Manager class
Manager::Manager() {
}
Manager::~Manager() {
for(Interface* service : m_services) {
DeleteService(service->GetPortName());
}
}
/// Add a service to the manager (does not create it though)
void Manager::AddService(Interface* service) { void Manager::AddService(Interface* service) {
// TOOD(yuriks): Fix error reporting // TOOD(yuriks): Fix error reporting
m_port_map[service->GetPortName()] = Kernel::g_handle_table.Create(service).ValueOr(INVALID_HANDLE); m_port_map[service->GetPortName()] = Kernel::g_handle_table.Create(service).ValueOr(INVALID_HANDLE);
m_services.push_back(service); m_services.push_back(service);
} }
/// Removes a service from the manager, also frees memory
void Manager::DeleteService(const std::string& port_name) { void Manager::DeleteService(const std::string& port_name) {
Interface* service = FetchFromPortName(port_name); Interface* service = FetchFromPortName(port_name);
m_services.erase(std::remove(m_services.begin(), m_services.end(), service), m_services.end()); m_services.erase(std::remove(m_services.begin(), m_services.end(), service), m_services.end());
m_port_map.erase(port_name); m_port_map.erase(port_name);
delete service;
} }
/// Get a Service Interface from its Handle
Interface* Manager::FetchFromHandle(Handle handle) { Interface* Manager::FetchFromHandle(Handle handle) {
return Kernel::g_handle_table.Get<Interface>(handle); return Kernel::g_handle_table.Get<Interface>(handle);
} }
/// Get a Service Interface from its port
Interface* Manager::FetchFromPortName(const std::string& port_name) { Interface* Manager::FetchFromPortName(const std::string& port_name) {
auto itr = m_port_map.find(port_name); auto itr = m_port_map.find(port_name);
if (itr == m_port_map.end()) { if (itr == m_port_map.end()) {

View File

@ -114,29 +114,22 @@ private:
/// Simple class to manage accessing services from ports and UID handles /// Simple class to manage accessing services from ports and UID handles
class Manager { class Manager {
public: public:
Manager(); /// Add a service to the manager
~Manager();
/// Add a service to the manager (does not create it though)
void AddService(Interface* service); void AddService(Interface* service);
/// Removes a service from the manager (does not delete it though) /// Removes a service from the manager
void DeleteService(const std::string& port_name); void DeleteService(const std::string& port_name);
/// Get a Service Interface from its UID /// Get a Service Interface from its Handle
Interface* FetchFromHandle(u32 uid); Interface* FetchFromHandle(Handle handle);
/// Get a Service Interface from its port /// Get a Service Interface from its port
Interface* FetchFromPortName(const std::string& port_name); Interface* FetchFromPortName(const std::string& port_name);
private: private:
std::vector<Interface*> m_services; std::vector<Interface*> m_services;
std::map<std::string, u32> m_port_map; std::map<std::string, u32> m_port_map;
}; };
/// Initialize ServiceManager /// Initialize ServiceManager