Skip to content

Commit 11e50ea

Browse files
committed
Fix data race error
1 parent 5ffd242 commit 11e50ea

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Image.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,22 @@ import "C"
3030

3131
type Image struct {
3232
p *C.struct_liq_image
33+
dataP unsafe.Pointer
3334
w, h int
3435
released bool
3536
}
3637

3738
// Callers MUST call Release() on the returned object to free memory.
3839
func NewImage(attr *Attributes, rgba32data string, width, height int, gamma float64) (*Image, error) {
3940
dataP := unsafe.Pointer(C.CString(rgba32data))
40-
defer C.free(dataP)
41-
4241
pImg := C.liq_image_create_rgba(attr.p, dataP, C.int(width), C.int(height), C.double(gamma))
4342
if pImg == nil {
4443
return nil, errors.New("Failed to create image (invalid argument)")
4544
}
4645
return &Image{
47-
p: pImg,
48-
w: width,
49-
//dataPointer: data,
46+
p: pImg,
47+
w: width,
48+
dataP: dataP,
5049
h: height,
5150
released: false,
5251
}, nil
@@ -55,6 +54,7 @@ func NewImage(attr *Attributes, rgba32data string, width, height int, gamma floa
5554
// Free memory. Callers must not use this object after Release has been called.
5655
func (this *Image) Release() {
5756
C.liq_image_destroy(this.p)
57+
C.free(this.dataP)
5858
this.released = true
5959
}
6060

0 commit comments

Comments
 (0)