diff --git a/mat_noprofile.go b/mat_noprofile.go index 5cc82a38..0d6d56a5 100644 --- a/mat_noprofile.go +++ b/mat_noprofile.go @@ -7,6 +7,7 @@ package gocv #include "core.h" */ import "C" +import "errors" // addMatToProfile does nothing if matprofile tag is not set. func addMatToProfile(p C.Mat) { @@ -20,6 +21,9 @@ func newMat(p C.Mat) Mat { // Close the Mat object. func (m *Mat) Close() error { + if m.p == nil { + return errors.New("duplicate Mat close") + } C.Mat_Close(m.p) m.p = nil m.d = nil diff --git a/mat_profile.go b/mat_profile.go index eaeaca8b..1caadd7c 100644 --- a/mat_profile.go +++ b/mat_profile.go @@ -73,6 +73,9 @@ func newMat(p C.Mat) Mat { // Close the Mat object. func (m *Mat) Close() error { + if m.p == nil { + return errors.New("duplicate Mat close") + } // NOTE: The pointer must be removed from the profile before it is deleted to // avoid a data race. MatProfile.Remove(m.p)