[eigen] CholmodSupport.h in Eigen 3.1 alpha returns a mapped matrix then frees the storage being mapped. |

[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]

*To*: eigen@xxxxxxxxxxxxxxxxxxx
*Subject*: [eigen] CholmodSupport.h in Eigen 3.1 alpha returns a mapped matrix then frees the storage being mapped.
*From*: Douglas Bates <bates@xxxxxxxxxxxxx>
*Date*: Tue, 6 Dec 2011 17:00:27 -0600
*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=NVOExupwkBceEcbK9kQ6B2KRdbT3K7vssBEY0juQbJo=; b=qwHhOK4MHk7dRMVKd04+R0zqo5NW2cSnBHShni+AXccs4zOkeHScHXk3Icq6UAwbqY 56mhLLE1tCO36Fnb/61hPxqL24eu+cn5eAA9V+EQr8Ayls7fGCBGe8CVJagU3PRgW8AH kuT4lHGi2YWiWjAlafIAVDYvoxFXl7jOz3rDY=

I mentioned this once before but did not get around to creating an
test case to show the problem. In CholmodSupport.h the internal
_solve functions assign a mapped dense or sparse matrix to the dest
reference and then free the storage that is mapped.
For example, in the dense case the _solve function ends with
dest = Matrix<Scalar,Dest::RowsAtCompileTime,Dest::ColsAtCompileTime>::Map(reinterpret_cast<Scalar*>(x_cd->x),b.rows(),b.cols());
cholmod_free_dense(&x_cd, &m_cholmod);
One of the side-effects of cholmod_free_dense is to free the storage
to which x_cd->x points.
I think that the tests in eigen/unsupported/test/sparse_llt.cpp pass
because the value is tested immediately and the freed storage has not
been overwritten.
I'm not exactly sure how to create a test case to show the problem.
By default Cholmod uses malloc/free for dynamic storage and I'm not
sure how this interacts with the C++ dynamic storage allocation for
objects. I would like to ensure that the freed chunk of storage
pointed to by x_cd->x is overwritten after the result has been
returned but that involves knowing more about malloc, etc. than I do.