--- php_gearman.orig.c	1970-01-01 10:13:08.000000000 +0100
+++ php_gearman.c	2009-10-24 22:16:05.000000000 +0200
@@ -1075,6 +1075,13 @@
 }
 
 void _php_task_free(gearman_task_st *task, void *context) {
+	/* libgearman will set the context to the client itself if the user
+	   simply did ->do*. In those cases we've not created any references. */
+	if (task->client == context)
+	{
+		return;
+	}
+
 	gearman_task_obj *obj= (gearman_task_obj *)context;
     TSRMLS_FETCH();
 
