Skip to content

Commit

Permalink
Fix possible resource leak
Browse files Browse the repository at this point in the history
  • Loading branch information
andriikushch authored and deadprogram committed Aug 14, 2019
1 parent 0a03de5 commit be8caa6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
7 changes: 4 additions & 3 deletions contrib/tracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ func TestSingleTrackers(t *testing.T) {
}

for _, test := range tab {
defer test.tracker.Close()

BaseTestTracker(t, test.tracker, test.name)
func() {
defer test.tracker.Close()
BaseTestTracker(t, test.tracker, test.name)
}()
}
}
52 changes: 28 additions & 24 deletions imgproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,22 +1154,24 @@ func FillPoly(img *Mat, pts [][]image.Point, c color.RGBA) {
points := make([]C.struct_Points, len(pts))

for i, pt := range pts {
p := (*C.struct_Point)(C.malloc(C.size_t(C.sizeof_struct_Point * len(pt))))
defer C.free(unsafe.Pointer(p))
func() {
p := (*C.struct_Point)(C.malloc(C.size_t(C.sizeof_struct_Point * len(pt))))
defer C.free(unsafe.Pointer(p))

pa := getPoints(p, len(pt))
pa := getPoints(p, len(pt))

for j, point := range pt {
pa[j] = C.struct_Point{
x: C.int(point.X),
y: C.int(point.Y),
for j, point := range pt {
pa[j] = C.struct_Point{
x: C.int(point.X),
y: C.int(point.Y),
}
}
}

points[i] = C.struct_Points{
points: (*C.Point)(p),
length: C.int(len(pt)),
}
points[i] = C.struct_Points{
points: (*C.Point)(p),
length: C.int(len(pt)),
}
}()
}

cPoints := C.struct_Contours{
Expand Down Expand Up @@ -1433,22 +1435,24 @@ func DrawContours(img *Mat, contours [][]image.Point, contourIdx int, c color.RG
cntrs := make([]C.struct_Points, len(contours))

for i, contour := range contours {
p := (*C.struct_Point)(C.malloc(C.size_t(C.sizeof_struct_Point * len(contour))))
defer C.free(unsafe.Pointer(p))
func() {
p := (*C.struct_Point)(C.malloc(C.size_t(C.sizeof_struct_Point * len(contour))))
defer C.free(unsafe.Pointer(p))

pa := getPoints(p, len(contour))
pa := getPoints(p, len(contour))

for j, point := range contour {
pa[j] = C.struct_Point{
x: C.int(point.X),
y: C.int(point.Y),
for j, point := range contour {
pa[j] = C.struct_Point{
x: C.int(point.X),
y: C.int(point.Y),
}
}
}

cntrs[i] = C.struct_Points{
points: (*C.Point)(p),
length: C.int(len(contour)),
}
cntrs[i] = C.struct_Points{
points: (*C.Point)(p),
length: C.int(len(contour)),
}
}()
}

cContours := C.struct_Contours{
Expand Down

0 comments on commit be8caa6

Please sign in to comment.