Ticket #10085: 10085.patch

File 10085.patch, 1.2 KB (added by danielk, 13 years ago)
  • mythplugins/mytharchive/mytharchivehelper/main.cpp

    diff --git a/mythplugins/mytharchive/mytharchivehelper/main.cpp b/mythplugins/mytharchive/mytharchivehelper/main.cpp
    index 92b041f..ea33aef 100644
    a b extern "C" { 
    7575// mytharchive headers
    7676#include "../mytharchive/archiveutil.h"
    7777
     78namespace
     79{
     80    void cleanup()
     81    {
     82        delete gContext;
     83        gContext = NULL;
     84    }
     85
     86    class CleanupGuard
     87    {
     88      public:
     89        typedef void (*CleanupFunc)();
     90
     91      public:
     92        CleanupGuard(CleanupFunc cleanFunction) :
     93            m_cleanFunction(cleanFunction) {}
     94
     95        ~CleanupGuard()
     96        {
     97            m_cleanFunction();
     98        }
     99
     100      private:
     101        CleanupFunc m_cleanFunction;
     102    };
     103}
     104
    78105class NativeArchive
    79106{
    80107  public:
    int main(int argc, char **argv) 
    26252652    // Don't listen to console input
    26262653    close(0);
    26272654
     2655    CleanupGuard callCleanup(cleanup);
    26282656    gContext = new MythContext(MYTH_BINARY_VERSION);
    26292657    if (!gContext->Init(false))
    26302658    {
    26312659        LOG(VB_GENERAL, LOG_ERR, "Failed to init MythContext, exiting.");
    2632         delete gContext;
    26332660        return GENERIC_EXIT_NO_MYTHCONTEXT;
    26342661    }
    26352662