Index: Singular/attrib.cc
===================================================================
--- Singular/attrib.cc	(revision 7bd06876c68417663814d23718236d06ed4f91b3)
+++ Singular/attrib.cc	(revision 2dbaba417a5adc322a3e679319b2ded708f31ea6)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: attrib.cc,v 1.33 2009-03-18 16:35:54 Singular Exp $ */
+/* $Id: attrib.cc,v 1.34 2009-05-05 09:54:38 Singular Exp $ */
 
 /*
@@ -194,5 +194,5 @@
 }
 
-void sattr::kill()
+void sattr::kill(const ring r)
 {
   omFree((ADDRESS)name);
@@ -206,9 +206,9 @@
   case MODUL_CMD:
   case MATRIX_CMD:
-    idDelete((ideal *)&data);
+    id_Delete((ideal *)&data,r);
     break;
   case POLY_CMD:
   case VECTOR_CMD:
-    pDelete((poly *)&data);
+    p_Delete((poly *)&data,r);
     break;
   case INT_CMD:
@@ -226,5 +226,5 @@
 }
 
-void sattr::killAll()
+void sattr::killAll(const ring r)
 {
   attr temp = this,temp1;
@@ -233,10 +233,10 @@
   {
     temp1 = temp->next;
-    temp->kill();
+    temp->kill(r);
     temp = temp1;
   }
 }
 
-void atKill(idhdl root,const char * name)
+void at_Kill(idhdl root,const char * name, const ring r)
 {
   attr temp = root->attribute->get(name);
@@ -254,11 +254,11 @@
       temp1->next = N;
     }
-    temp->kill();
-  }
-}
-
-void atKillAll(idhdl root)
-{
-  root->attribute->killAll();
+    temp->kill(r);
+  }
+}
+
+void at_KillAll(idhdl root, const ring r)
+{
+  root->attribute->killAll(r);
   root->attribute = NULL;
 }
Index: Singular/attrib.h
===================================================================
--- Singular/attrib.h	(revision 7bd06876c68417663814d23718236d06ed4f91b3)
+++ Singular/attrib.h	(revision 2dbaba417a5adc322a3e679319b2ded708f31ea6)
@@ -4,5 +4,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: attrib.h,v 1.8 2008-03-19 17:44:29 Singular Exp $ */
+/* $Id: attrib.h,v 1.9 2009-05-05 09:54:37 Singular Exp $ */
 /*
 * ABSTRACT: attributes to leftv and idhdl
@@ -28,6 +28,6 @@
     attr set(const char * s, void * data, int t);
     attr get(const char * s);
-    void kill();
-    void killAll();
+    void kill(const ring r);
+    void killAll(const ring r);
 };
 
@@ -38,6 +38,8 @@
 void atSet(idhdl root,const char * name,void * data,int typ);
 void atSet(leftv root,const char * name,void * data,int typ);
-void atKillAll(idhdl root);
-void atKill(idhdl root,const char * name);
+void at_KillAll(idhdl root,const ring r);
+#define atKillAll(H) at_KillAll(H,currRing)
+void at_Kill(idhdl root,const char * name,const ring r);
+#define atKill(H,A) at_Kill(H,A,currRing)
 
 BOOLEAN atATTRIB1(leftv res,leftv a);
Index: Singular/ipid.cc
===================================================================
--- Singular/ipid.cc	(revision 7bd06876c68417663814d23718236d06ed4f91b3)
+++ Singular/ipid.cc	(revision 2dbaba417a5adc322a3e679319b2ded708f31ea6)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: ipid.cc,v 1.85 2009-05-04 15:06:15 Singular Exp $ */
+/* $Id: ipid.cc,v 1.86 2009-05-05 09:54:38 Singular Exp $ */
 
 /*
@@ -539,5 +539,5 @@
   if (h->attribute!=NULL)
   {
-    atKillAll(h);
+    at_KillAll(h,r);
     //h->attribute=NULL;
   }
Index: Singular/ipshell.cc
===================================================================
--- Singular/ipshell.cc	(revision 7bd06876c68417663814d23718236d06ed4f91b3)
+++ Singular/ipshell.cc	(revision 2dbaba417a5adc322a3e679319b2ded708f31ea6)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: ipshell.cc,v 1.204 2009-05-04 15:06:16 Singular Exp $ */
+/* $Id: ipshell.cc,v 1.205 2009-05-05 09:54:37 Singular Exp $ */
 /*
 * ABSTRACT:
@@ -5060,23 +5060,4 @@
     if (traceit &TRACE_SHOW_RINGS) Print("kill ring %lx\n",(long)r);
 #endif
-    if (r==currRing)
-    {
-      if (r->qideal!=NULL)
-      {
-        currQuotient=NULL;
-      }
-      if (ppNoether!=NULL) pDelete(&ppNoether);
-      if (sLastPrinted.RingDependend())
-      {
-        sLastPrinted.CleanUp();
-      }
-      if ((myynest>0) && (iiRETURNEXPR[myynest].RingDependend()))
-      {
-        WerrorS("return value depends on local ring variable (export missing ?)");
-        iiRETURNEXPR[myynest].CleanUp();
-      }
-      currRing=NULL;
-      currRingHdl=NULL;
-    }
     if (r->qideal!=NULL)
     {
@@ -5117,4 +5098,24 @@
     {
       killhdl2(r->idroot,&(r->idroot),r);
+    }
+    if (r==currRing)
+    {
+      // all dependend stuff is done, clean global vars:
+      if (r->qideal!=NULL)
+      {
+        currQuotient=NULL;
+      }
+      if (ppNoether!=NULL) pDelete(&ppNoether);
+      if (sLastPrinted.RingDependend())
+      {
+        sLastPrinted.CleanUp();
+      }
+      if ((myynest>0) && (iiRETURNEXPR[myynest].RingDependend()))
+      {
+        WerrorS("return value depends on local ring variable (export missing ?)");
+        iiRETURNEXPR[myynest].CleanUp();
+      }
+      currRing=NULL;
+      currRingHdl=NULL;
     }
 
Index: Singular/subexpr.cc
===================================================================
--- Singular/subexpr.cc	(revision 7bd06876c68417663814d23718236d06ed4f91b3)
+++ Singular/subexpr.cc	(revision 2dbaba417a5adc322a3e679319b2ded708f31ea6)
@@ -5,5 +5,5 @@
 * ABSTRACT: handling of leftv
 */
-/* $Id: subexpr.cc,v 1.103 2009-02-20 18:39:21 Singular Exp $ */
+/* $Id: subexpr.cc,v 1.104 2009-05-05 09:54:38 Singular Exp $ */
 
 #include <stdlib.h>
@@ -406,5 +406,5 @@
         {
           t=attribute->next;
-          attribute->kill();
+          attribute->kill(currRing);
           attribute=t;
         }
