diff --git a/src/interpret.c b/src/interpret.c
index a64f7845612e1333ede30d47b24d22d233e1354c..a57c78bd83d6997d495cf98040dabce405a4db3a 100644
--- a/src/interpret.c
+++ b/src/interpret.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: interpret.c,v 1.171 2000/09/25 23:41:33 hubbe Exp $");
+RCSID("$Id: interpret.c,v 1.172 2000/10/01 08:51:52 hubbe Exp $");
 #include "interpret.h"
 #include "object.h"
 #include "program.h"
@@ -441,7 +441,7 @@ PMOD_EXPORT void find_external_context(struct external_variable_context *loc,
   struct program *p;
   INT32 e,off;
   TRACE((4, "-find_external_context(%d, inherit=%ld)\n", arg2,
-	 DO_NOT_WARN((long)(loc->inherit - loc->o->prog->inherits))));
+	 DO_NOT_WARN((long)(loc->o->prog ? loc->inherit - loc->o->prog->inherits : 0))));
 
   if(!loc->o)
     error("Current object is destructed\n");
@@ -449,7 +449,7 @@ PMOD_EXPORT void find_external_context(struct external_variable_context *loc,
   while(--arg2>=0)
   {
 #ifdef PIKE_DEBUG  
-    if(t_flag>8)
+    if(t_flag>8 && loc->o->prog)
       my_describe_inherit_structure(loc->o->prog);
 #endif
 
diff --git a/src/object.c b/src/object.c
index 262c9876d8a462ab508064175fbd3fcc9217cf7e..8ebe234458292aa81ef602551df0cc5323fdcfe3 100644
--- a/src/object.c
+++ b/src/object.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: object.c,v 1.149 2000/09/29 15:48:04 mast Exp $");
+RCSID("$Id: object.c,v 1.150 2000/10/01 08:51:53 hubbe Exp $");
 #include "object.h"
 #include "dynamic_buffer.h"
 #include "interpret.h"
@@ -468,10 +468,19 @@ struct destroy_called_mark
 {
   struct destroy_called_mark *next;
   void *data;
+  struct program *p; /* for magic */
 };
 
 PTR_HASH_ALLOC(destroy_called_mark,128)
 
+PMOD_EXPORT struct program *get_program_for_object_being_destructed(struct object * o)
+{
+  struct destroy_called_mark * tmp;
+  if(( tmp = find_destroy_called_mark(o)))
+    return tmp->p;
+  return 0;
+}
+
 static void call_destroy(struct object *o, int foo)
 {
   int e;
@@ -520,6 +529,7 @@ static void call_destroy(struct object *o, int foo)
 #endif
 }
 
+
 void low_destruct(struct object *o,int do_free)
 {
   int e;
@@ -537,7 +547,6 @@ void low_destruct(struct object *o,int do_free)
   add_ref(o);
 
   call_destroy(o,0);
-  remove_destroy_called_mark(o);
 
   /* destructed in destroy() */
   if(!(p=o->prog))
@@ -545,6 +554,7 @@ void low_destruct(struct object *o,int do_free)
     free_object(o);
     return;
   }
+  get_destroy_called_mark(o)->p=p;
 
   debug_malloc_touch(o);
   debug_malloc_touch(o->storage);
@@ -610,6 +620,8 @@ void low_destruct(struct object *o,int do_free)
   POP_FRAME();
 
   free_program(p);
+
+  remove_destroy_called_mark(o);
 }
 
 PMOD_EXPORT void destruct(struct object *o)
diff --git a/src/object.h b/src/object.h
index a520c400580d8489cf25a27e427de4f14c10b644..cc9ca2bb2bf5dc4e899c34ac1665482edf84b145 100644
--- a/src/object.h
+++ b/src/object.h
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: object.h,v 1.54 2000/08/10 14:58:05 grubba Exp $
+ * $Id: object.h,v 1.55 2000/10/01 08:51:54 hubbe Exp $
  */
 #ifndef OBJECT_H
 #define OBJECT_H
@@ -54,6 +54,7 @@ extern struct program *magic_set_index_program;
 #include "block_alloc_h.h"
 /* Prototypes begin here */
 BLOCK_ALLOC(object, 511)
+PMOD_EXPORT struct program *get_program_for_object_being_destructed(struct object * o);
 struct object *low_clone(struct program *p);
 void call_c_initializers(struct object *o);
 PMOD_EXPORT void do_free_object(struct object *o);
diff --git a/src/program.c b/src/program.c
index ef94f2c0b456f1182ab4c2bf5d9f0fafeb4fcb4c..bf13a1fe2a8ece9f9e2eea5b3c62e1a70a4720f8 100644
--- a/src/program.c
+++ b/src/program.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: program.c,v 1.273 2000/09/26 00:17:47 hubbe Exp $");
+RCSID("$Id: program.c,v 1.274 2000/10/01 08:51:54 hubbe Exp $");
 #include "program.h"
 #include "object.h"
 #include "dynamic_buffer.h"
@@ -4407,13 +4407,23 @@ int yyexplain_not_implements(struct program *a, struct program *b, int flags)
 PMOD_EXPORT void *parent_storage(int depth)
 {
   struct external_variable_context loc;
+  struct program *p;
+
 
   loc.o=Pike_fp->current_object;
-  if(!loc.o->prog)
-    error("Cannot access parent of destructed object.\n");
+  p=loc.o->prog;
+  if(!p)
+  {
+    /* magic fallback */
+    p=get_program_for_object_being_destructed(loc.o);
+    if(!p)
+    {
+      error("Cannot access parent of destructed object.\n");
+    }
+  }
 
   loc.parent_identifier=Pike_fp->fun;
-  loc.inherit=INHERIT_FROM_INT(loc.o->prog, Pike_fp->fun);
+  loc.inherit=INHERIT_FROM_INT(p, Pike_fp->fun);
   
   find_external_context(&loc, depth);