Permalink
Browse files

Fixed bug that caused the plugin to crash when reloading the plugin o…

…n serveral pages
  • Loading branch information...
1 parent 2f7865c commit 6d7f2dbc6f385ea5da387a0f2feae08bbf246e8d @adiesner committed Nov 21, 2011
Showing with 16 additions and 4 deletions.
  1. +16 −4 src/main.cpp
View
@@ -54,7 +54,7 @@ const char * pluginName = "Garmin Communicator";
/**
* A variable that stores the plugin description (may contain HTML)
*/
-const char * pluginDescription = "<a href=\"http://www.andreas-diesner.de/garminplugin/\">Garmin Communicator - Fake</a> plugin. Version 0.3.5";
+const char * pluginDescription = "<a href=\"http://www.andreas-diesner.de/garminplugin/\">Garmin Communicator - Fake</a> plugin. Version 0.3.6";
/**
* A variable that stores the mime description of the plugin.
@@ -87,6 +87,11 @@ static NPNetscapeFuncs *npnfuncs = NULL;
*/
static NPP inst = NULL;
+/**
+ * Counts the number of new's that have been executed on the plugin
+ */
+static int instanceCount = 0;
+
/**
* Stores the information about plugin properties
* All these properties can be accessed from the outside. They are stored
@@ -1872,6 +1877,7 @@ static NPClass npcRefObject = {
* @param saved ?
*/
static NPError nevv(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved) {
+ instanceCount++;
inst = instance;
if (Log::enabledDbg()) Log::dbg("new");
@@ -1950,10 +1956,16 @@ static NPError nevv(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t
* @return NPERR_NO_ERROR
*/
static NPError destroy(NPP instance, NPSavedData **save) {
- if(so)
- npnfuncs->releaseobject(so);
- so = NULL;
if (Log::enabledDbg()) Log::dbg("destroy");
+ instanceCount--;
+ if (instanceCount == 0) {
+ if (Log::enabledDbg()) Log::dbg("destroy - last instance");
+ if ((so) && (npnfuncs != NULL)) {
+ npnfuncs->releaseobject(so);
+ so = NULL;
+ }
+ }
+
return NPERR_NO_ERROR;
}

0 comments on commit 6d7f2db

Please sign in to comment.