From cfad8a8ae94d2d4b9461e25191241e38f0b4e693 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Tue, 6 May 2014 11:13:48 +0200
Subject: [PATCH] Backend: Invalidate the call_out id when stale.

Reduce garbage by not keeping references to arguments for dead call_outs.

It is not unusual for a call_out user to keep the call_out id until
the next time the call_out is needed. As these quite often cause
circular references, we need to zap them when they're no longer needed.
---
 src/backend.cmod | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/backend.cmod b/src/backend.cmod
index ea224451c3..826a0eaa88 100644
--- a/src/backend.cmod
+++ b/src/backend.cmod
@@ -992,7 +992,18 @@ PIKECLASS Backend
 	 cc->pos = -1;
 
 	 args = cc->args->size;
-	 push_array_items(cc->args);
+	 if (cc->args->refs == 1) {
+	   push_array_items(cc->args);
+	 } else {
+	   /* Somebody else also has references to the call_out id array.
+	    *
+	    * We need to clear it to reduce garbage.
+	    */
+	   add_ref(cc->args);
+	   push_array_items(cc->args);
+	   clear_array(cc->args);
+	   free_array(cc->args);
+	 }
 	 cc->args = NULL;
 	 free_object(cc->this);
 
@@ -1290,6 +1301,11 @@ PIKECLASS Backend
 	 SET_SVAL(*Pike_sp, T_INT, NUMBER_UNDEFINED, integer, -1);
 	 Pike_sp++;
        }
+
+       /* Make sure not to keep any references in the
+	* now stale co_info array. */
+       clear_array(co_info);
+
        free_array(co_info);
        backend_verify_call_outs(me);
        UNPROTECT_CALL_OUTS();
-- 
GitLab