Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision d7ae173cf134120772957b4772d6b5ac2ccb9806)
+++ src/GenPoly/Box.cc	(revision 6312b1c59df970f3d77597b98cd68dc5fd8dd3ec)
@@ -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 ) ) );
