summary refs log tree commit diff stats
path: root/plugins/python
diff options
context:
space:
mode:
authorArnavion <arnavion@gmail.com>2013-05-14 01:23:46 -0700
committerArnavion <arnavion@gmail.com>2013-05-14 01:25:01 -0700
commit5c9652bf13278a783928bcefeb856fdda55891a8 (patch)
tree156887c9485f7699e333bcd4b6f9005e79d49ff5 /plugins/python
parent631664645deee766d90c431fae6896da0fe821c9 (diff)
python: Hold a reference to plugin instead of dereferencing hook to get to it.
hook might have been free'd by the callback via hexchat.unhook().
Diffstat (limited to 'plugins/python')
-rw-r--r--plugins/python/python.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/plugins/python/python.c b/plugins/python/python.c
index 0fed65ca..d5a2aba8 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -498,18 +498,20 @@ Callback_Command(char *word[], char *word_eol[], void *userdata)
 	PyObject *retobj;
 	PyObject *word_list, *word_eol_list;
 	int ret = 0;
+	PyObject *plugin;
 
-	BEGIN_PLUGIN(hook->plugin);
+	plugin = hook->plugin;
+	BEGIN_PLUGIN(plugin);
 
 	word_list = Util_BuildList(word+1);
 	if (word_list == NULL) {
-		END_PLUGIN(hook->plugin);
+		END_PLUGIN(plugin);
 		return 0;
 	}
 	word_eol_list = Util_BuildList(word_eol+1);
 	if (word_eol_list == NULL) {
 		Py_DECREF(word_list);
-		END_PLUGIN(hook->plugin);
+		END_PLUGIN(plugin);
 		return 0;
 	}
 
@@ -528,7 +530,7 @@ Callback_Command(char *word[], char *word_eol[], void *userdata)
 		PyErr_Print();
 	}
 
-	END_PLUGIN(hook->plugin);
+	END_PLUGIN(plugin);
 
 	return ret;
 }
@@ -548,6 +550,7 @@ Callback_Print(char *word[], void *userdata)
 	int next = 0;
 	int i;
 	int ret = 0;
+	PyObject *plugin;
 
 	/* Cut off the message identifier. */
 	word += 1;
@@ -579,13 +582,14 @@ Callback_Print(char *word[], void *userdata)
 	}
 	word_eol[i] = "";
 
-	BEGIN_PLUGIN(hook->plugin);
+	plugin = hook->plugin;
+	BEGIN_PLUGIN(plugin);
 
 	word_list = Util_BuildList(word);
 	if (word_list == NULL) {
 		g_free(word_eol_raw);
 		g_free(word_eol);
-		END_PLUGIN(hook->plugin);
+		END_PLUGIN(plugin);
 		return 0;
 	}
 	word_eol_list = Util_BuildList(word_eol);
@@ -593,7 +597,7 @@ Callback_Print(char *word[], void *userdata)
 		g_free(word_eol_raw);
 		g_free(word_eol);
 		Py_DECREF(word_list);
-		END_PLUGIN(hook->plugin);
+		END_PLUGIN(plugin);
 		return 0;
 	}
 
@@ -614,7 +618,7 @@ Callback_Print(char *word[], void *userdata)
 		PyErr_Print();
 	}
 
-	END_PLUGIN(hook->plugin);
+	END_PLUGIN(plugin);
 
 	return ret;
 }