Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision 3e5dd91354f39b161547cc1119ecef5890aa765f)
+++ src/GenPoly/Box.cc	(revision ef1d025d1b14c99e152c1343b694fc21441cc013)
@@ -1525,4 +1525,15 @@
 					stmtsToAddBefore.push_back( new DeclStmt( newBuf ) );
 
+					// if the object has a cleanup attribute, the cleanup should be on the buffer, not the pointer
+					auto matchAndMove = [newBuf](Attribute * attr){
+						if(attr->name == "cleanup") {
+							newBuf->attributes.push_back(attr);
+							return true;
+						}
+						return false;
+					};
+
+					objectDecl->attributes.remove_if(matchAndMove);
+
 					delete objectDecl->get_init();
 					objectDecl->set_init( new SingleInit( new VariableExpr( newBuf ) ) );
