Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
Attempt to explicitly terminate our singletons.
Browse files Browse the repository at this point in the history
This ensures that any global objects are *definitely* cleaned
and freeds when the process terminates.

The intention is that this will allow real leaks to be detected
more easily, via valgrind.

This updates #287.
  • Loading branch information
skx committed Apr 9, 2017
1 parent a1275d0 commit 44a1672
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CGlobalState : public Singleton<CGlobalState>, public Observer
/**
* Destructor.
*/
~CGlobalState();
virtual ~CGlobalState();

public:

Expand Down
2 changes: 1 addition & 1 deletion src/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CLua : public Singleton<CLua>, public Observer

public:
CLua();
~CLua();
virtual ~CLua();

public:

Expand Down
22 changes: 22 additions & 0 deletions src/lumail2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
#include "config.h"
#include "file.h"
#include "global_state.h"
#include "history.h"
#include "imap_proxy.h"
#include "input_queue.h"
#include "logger.h"
#include "lua.h"
#include "maildir.h"
#include "message.h"
#include "message_part.h"
#include "mime.h"
#include "screen.h"
#include "statuspanel.h"
#include "tests.h"

/*
Expand Down Expand Up @@ -252,6 +257,23 @@ int main(int argc, char *argv[])
CIMAPProxy *proxy = CIMAPProxy::instance();
proxy->terminate();

/*
* Now we terminate all our singletons in an aim
* to explicitly free memory and make leak-detection
* simpler.
*/
config->destroy_instance();
proxy->destroy_instance();

CHistory::instance()->destroy_instance();
CGlobalState::instance()->destroy_instance();
CInputQueue::instance()->destroy_instance();
CStatusPanel::instance()->destroy_instance();
CScreen::instance()->destroy_instance();
CMime::instance()->destroy_instance();
CLua::instance()->destroy_instance();
CLogger::instance()->destroy_instance();

/*
* Close GMime.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CScreen : public Singleton<CScreen>, public Observer
/**
* Destructor.
*/
~CScreen();
virtual ~CScreen();

/**
* Register a view mode.
Expand Down

0 comments on commit 44a1672

Please sign in to comment.