diff --git a/src/program.c b/src/program.c
index 7234bcf49446b9dbba20204ad350b1f33c2bfeb1..5eeca8890005efae48324fc3718971f9b87e70a4 100644
--- a/src/program.c
+++ b/src/program.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: program.c,v 1.741 2008/08/13 18:02:02 mast Exp $
+|| $Id: program.c,v 1.742 2008/08/13 21:11:58 mast Exp $
 */
 
 #include "global.h"
@@ -8011,6 +8011,11 @@ static void run_cleanup(struct compilation *c, int delayed)
       SAFE_APPLY_MASTER("unregister",1);
       pop_stack();
 
+      /* Free the target here to avoid false alarms in the debug check
+       * below. */
+      free_program (c->target);
+      c->target = NULL;
+
 #ifdef PIKE_DEBUG
       if (p->refs > 1) {
 	/* Other programs can have indexed out constants from p, which