Revise CMatrix avoid memory leak

Prevent memory leak