Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic if repeat defer mat.Close #899

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mat_noprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions mat_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down