- mozilla: some cleanup, workarounds for potential crash scenarios
authorDamien Fouilleul <damienf@videolan.org>
Tue, 20 Mar 2007 00:11:57 +0000 (00:11 +0000)
committerDamien Fouilleul <damienf@videolan.org>
Tue, 20 Mar 2007 00:11:57 +0000 (00:11 +0000)
mozilla/control/npolibvlc.cpp
mozilla/control/npolibvlc.h
mozilla/control/nporuntime.h
mozilla/vlcshell.cpp

index 4a13d3e..12e3cc1 100755 (executable)
@@ -31,8 +31,8 @@
 #   include <mozilla-config.h>\r
 #endif\r
 \r
-#include "npolibvlc.h"\r
 #include "vlcplugin.h"\r
+#include "npolibvlc.h"\r
 \r
 /*\r
 ** implementation of libvlc root object\r
@@ -81,8 +81,8 @@ enum LibvlcRootNPObjectPropertyIds
 \r
 RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
         switch( index )\r
         {\r
@@ -137,8 +137,8 @@ enum LibvlcRootNPObjectMethodIds
 \r
 RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
@@ -193,9 +193,10 @@ enum LibvlcAudioNPObjectPropertyIds
 \r
 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -271,9 +272,10 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
 \r
 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -370,9 +372,10 @@ enum LibvlcAudioNPObjectMethodIds
 \r
 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -432,9 +435,10 @@ enum LibvlcInputNPObjectPropertyIds
 \r
 RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -558,9 +562,10 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari
 \r
 RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -680,8 +685,8 @@ enum LibvlcMessageNPObjectPropertyIds
 \r
 RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
         switch( index )\r
         {\r
@@ -784,9 +789,10 @@ LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const
     RuntimeNPObject(instance, aClass),\r
     _p_iter(NULL)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);\r
         libvlc_log_t *p_log = p_plugin->getLog();\r
         if( p_log )\r
         {\r
@@ -815,9 +821,10 @@ enum LibvlcMessageIteratorNPObjectPropertyIds
 \r
 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         switch( index )\r
         {\r
             case ID_messageiterator_hasNext:\r
@@ -862,9 +869,10 @@ enum LibvlcMessageIteratorNPObjectMethodIds
 \r
 RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -927,9 +935,10 @@ enum LibvlcMessagesNPObjectPropertyIds
 \r
 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         switch( index )\r
         {\r
             case ID_messages_count:\r
@@ -977,9 +986,10 @@ enum LibvlcMessagesNPObjectMethodIds
 \r
 RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -1033,7 +1043,7 @@ RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NP
 LibvlcLogNPObject::LibvlcLogNPObject(NPP instance, const NPClass *aClass) :\r
     RuntimeNPObject(instance, aClass)\r
 {\r
-    _p_vlcmessages = static_cast<LibvlcMessagesNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass()));\r
+    _p_vlcmessages = NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass());\r
 };\r
     \r
 LibvlcLogNPObject::~LibvlcLogNPObject()\r
@@ -1057,9 +1067,10 @@ enum LibvlcLogNPObjectPropertyIds
 \r
 RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -1099,9 +1110,10 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVarian
 \r
 RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -1181,9 +1193,10 @@ enum LibvlcPlaylistItemsNPObjectPropertyIds
 \r
 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -1224,9 +1237,10 @@ enum LibvlcPlaylistItemsNPObjectMethodIds
 \r
 RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -1281,7 +1295,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, con
 LibvlcPlaylistNPObject::LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :\r
     RuntimeNPObject(instance, aClass)\r
 {\r
-    _p_vlcplaylistitems = static_cast<LibvlcPlaylistItemsNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass()));\r
+    _p_vlcplaylistitems = NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());\r
 };\r
     \r
 LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()\r
@@ -1307,9 +1321,10 @@ enum LibvlcPlaylistNPObjectPropertyIds
 \r
 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -1381,9 +1396,10 @@ enum LibvlcPlaylistNPObjectMethodIds
 \r
 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -1429,7 +1445,10 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                         name = stringValue(NPVARIANT_TO_STRING(args[0]));\r
                     }\r
                     else\r
-                        return INVOKERESULT_NO_SUCH_METHOD;\r
+                    {\r
+                        delete url;\r
+                        return INVOKERESULT_INVALID_VALUE;\r
+                    }\r
                 }\r
 \r
                 int i_options = 0;\r
@@ -1451,6 +1470,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                     {\r
                         parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);\r
                     }\r
+                    else\r
+                    {\r
+                        delete url;\r
+                        delete name;\r
+                        return INVOKERESULT_INVALID_VALUE;\r
+                    }\r
                 }\r
 \r
                 int item = libvlc_playlist_add_extended(p_plugin->getVLC(),\r
@@ -1463,11 +1488,10 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                 delete name;\r
                 for( int i=0; i< i_options; ++i )\r
                 {\r
-                    if( ppsz_options[i] )\r
-                        free(ppsz_options[i]);\r
+                    delete ppsz_options[i];\r
                 }\r
-                if( ppsz_options )\r
-                    free(ppsz_options);\r
+                delete ppsz_options;\r
+\r
                 if( libvlc_exception_raised(&ex) )\r
                 {\r
                     NPN_SetException(this, libvlc_exception_get_message(&ex));\r
@@ -1778,9 +1802,10 @@ const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::prope
 \r
 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -1886,9 +1911,10 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVari
 \r
 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
@@ -1940,7 +1966,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const
                 }\r
 \r
                 libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex);\r
-                free(psz_aspect );\r
+                delete psz_aspect;\r
                 libvlc_input_free(p_input);\r
 \r
                 if( libvlc_exception_raised(&ex) )\r
@@ -1987,7 +2013,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const
                 }\r
 \r
                 libvlc_video_set_crop_geometry(p_input, psz_geometry, &ex);\r
-                free(psz_geometry );\r
+                delete psz_geometry;\r
                 libvlc_input_free(p_input);\r
 \r
                 if( libvlc_exception_raised(&ex) )\r
@@ -2018,9 +2044,10 @@ const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodN
 \r
 RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
 {\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
+    /* is plugin still running */\r
+    if( _instance->pdata )\r
     {\r
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
         libvlc_exception_t ex;\r
         libvlc_exception_init(&ex);\r
 \r
index 96be103..c018c0c 100755 (executable)
@@ -45,6 +45,7 @@ protected:
 \r
     InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
 \r
+private:\r
     NPObject *audioObj;\r
     NPObject *inputObj;\r
     NPObject *logObj;\r
@@ -184,7 +185,7 @@ protected:
     static const NPUTF8 * const methodNames[];\r
 \r
 private:\r
-    LibvlcMessagesNPObject* _p_vlcmessages;\r
+    NPObject* _p_vlcmessages;\r
 };\r
 \r
 class LibvlcPlaylistItemsNPObject: public RuntimeNPObject\r
@@ -229,7 +230,7 @@ protected:
     void parseOptions(NPObject *obj, int *i_options, char*** ppsz_options);\r
 \r
 private:\r
-    LibvlcPlaylistItemsNPObject* _p_vlcplaylistitems;\r
+    NPObject*  _p_vlcplaylistitems;\r
 };\r
 \r
 class LibvlcVideoNPObject: public RuntimeNPObject\r
index 4b15853..70d8917 100755 (executable)
@@ -69,12 +69,26 @@ public:
     static char* stringValue(const NPVariant &v);
 
 protected:
+    void *operator new(size_t n)
+    {
+        return NPN_MemAlloc(n);
+    };
+
+    void operator delete(void *p)
+    {
+        /*
+        ** Some memory scribble happens occasionally on freed object
+        ** when used on Firefox (MacOS X) and may cause crash, a leak
+        ** sounds like the better option.
+        */
+        //NPN_MemFree(p);
+    };
 
     RuntimeNPObject(NPP instance, const NPClass *aClass) :
         _instance(instance)
     {
         _class = const_cast<NPClass *>(aClass);
-        referenceCount = 1;
+        //referenceCount = 1;
     };
     virtual ~RuntimeNPObject() {};
 
@@ -149,12 +163,13 @@ template<class T>
 static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass)
 {
     const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(aClass);
-    return (NPObject *)vClass->create(instance);
+    return vClass->create(instance);
 }
 
 static void RuntimeNPClassDeallocate(NPObject *npobj)
 {
     RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
+    vObj->_class = NULL;
     delete vObj;
 }
 
@@ -181,12 +196,15 @@ static bool RuntimeNPClassHasProperty(NPObject *npobj, NPIdentifier name)
 template<class T>
 static bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result)
 {
-    const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
-    int index = vClass->indexOfProperty(name);
-    if( index != -1 )
+    RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
+    if( vObj->_instance )
     {
-        RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
-        return vObj->returnInvokeResult(vObj->getProperty(index, *result));
+        const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
+        int index = vClass->indexOfProperty(name);
+        if( index != -1 )
+        {
+            return vObj->returnInvokeResult(vObj->getProperty(index, *result));
+        }
     }
     return false;
 }
@@ -194,12 +212,15 @@ static bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVari
 template<class T>
 static bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value)
 {
-    const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
-    int index = vClass->indexOfProperty(name);
-    if( index != -1 )
+    RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
+    if( vObj->_instance )
     {
-        RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
-        return vObj->returnInvokeResult(vObj->setProperty(index, *value));
+        const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
+        int index = vClass->indexOfProperty(name);
+        if( index != -1 )
+        {
+            return vObj->returnInvokeResult(vObj->setProperty(index, *value));
+        }
     }
     return false;
 }
@@ -207,12 +228,15 @@ static bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const
 template<class T>
 static bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name)
 {
-    const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
-    int index = vClass->indexOfProperty(name);
-    if( index != -1 )
+    RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
+    if( vObj->_instance )
     {
-        RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
-        return vObj->returnInvokeResult(vObj->removeProperty(index));
+        const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
+        int index = vClass->indexOfProperty(name);
+        if( index != -1 )
+        {
+            return vObj->returnInvokeResult(vObj->removeProperty(index));
+        }
     }
     return false;
 }
@@ -222,13 +246,16 @@ static bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
                                     const NPVariant *args, uint32_t argCount,
                                     NPVariant *result)
 {
-    const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
-    int index = vClass->indexOfMethod(name);
-    if( index != -1 )
+    RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
+    if( vObj->_instance )
     {
-        RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
-        return vObj->returnInvokeResult(vObj->invoke(index, args, argCount, *result));
+        const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
+        int index = vClass->indexOfMethod(name);
+        if( index != -1 )
+        {
+            return vObj->returnInvokeResult(vObj->invoke(index, args, argCount, *result));
 
+        }
     }
     return false;
 }
@@ -239,7 +266,11 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
                                            NPVariant *result)
 {
     RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
-    return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result));
+    if( vObj->_instance )
+    {
+        return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result));
+    }
+    return false;
 }
 
 template<class T>
index 57e3c2b..e023fc4 100644 (file)
@@ -147,6 +147,12 @@ int16 NPP_HandleEvent( NPP instance, void * event )
     }
 
     VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
+
+    if( p_plugin == NULL )
+    {
+        return false;
+    }
+
     EventRecord *myEvent = (EventRecord*)event;
 
     switch( myEvent->what )
@@ -311,8 +317,7 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
     }
 #endif
 
-    if( p_plugin )
-        delete p_plugin;
+    delete p_plugin;
 
     return NPERR_NO_ERROR;
 }
@@ -479,6 +484,10 @@ NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
     }
 
     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
+    if( NULL == p_plugin )
+    {
+        return NPERR_INVALID_INSTANCE_ERROR;
+    }
 
    /*
    ** Firefox/Mozilla may decide to open a stream from the URL specified
@@ -529,6 +538,10 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
     }
 
     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
+    if( NULL == p_plugin )
+    {
+        return;
+    }
 
     if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) != -1 )
     {