fixed double free in vision/image resizePreserveAspectRatio and wrong ctype at libtch

This commit is contained in:
sugarme 2021-07-06 18:58:15 +10:00
parent 35b4732830
commit af8f999635
3 changed files with 8 additions and 10 deletions

View File

@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed `vision/aug` and correct ColorJitter
- Changed `vision/aug` and correct Resize
- Changed `dutil/sampler` to accept batchsize from 1.
- Fixed double free in `vision/image.go/resizePreserveAspectRatio`
- Fixed incorrect ctype `long` caused compiling error in MacOS as noted on [#44]
## [0.3.10]
- Update installation at README.md
@ -119,3 +121,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#26]: https://github.com/sugarme/gotch/issues/26
[#30]: https://github.com/sugarme/gotch/issues/30
[#32]: https://github.com/sugarme/gotch/issues/32
[#44]: https://github.com/sugarme/gotch/issues/44

View File

@ -96,7 +96,7 @@ func AtDim(t Ctensor) uint64 {
// void at_shape(tensor, int64_t *);
func AtShape(t Ctensor, ptr unsafe.Pointer) {
c_ptr := (*C.long)(ptr)
c_ptr := (*C.longlong)(ptr)
C.at_shape(t, c_ptr)
}
@ -137,7 +137,7 @@ func AtcSetBenchmarkCudnn(b int) {
// double at_double_value_at_indexes(tensor, int64_t *indexes, int indexes_len);
func AtDoubleValueAtIndexes(ts Ctensor, indexes unsafe.Pointer, indexesLen int) float64 {
ctensor := (C.tensor)(ts)
cindexes := (*C.long)(indexes)
cindexes := (*C.longlong)(indexes)
cindexesLen := *(*C.int)(unsafe.Pointer(&indexesLen))
retVal := C.at_double_value_at_indexes(ctensor, cindexes, cindexesLen)
return *(*float64)(unsafe.Pointer(&retVal))
@ -146,7 +146,7 @@ func AtDoubleValueAtIndexes(ts Ctensor, indexes unsafe.Pointer, indexesLen int)
// int64_t at_int64_value_at_indexes(tensor, int64_t *indexes, int indexes_len);
func AtInt64ValueAtIndexes(ts Ctensor, indexes unsafe.Pointer, indexesLen int) int64 {
ctensor := (C.tensor)(ts)
cindexes := (*C.long)(indexes)
cindexes := (*C.longlong)(indexes)
cindexesLen := *(*C.int)(unsafe.Pointer(&indexesLen))
retVal := C.at_int64_value_at_indexes(ctensor, cindexes, cindexesLen)
return *(*int64)(unsafe.Pointer(&retVal))

View File

@ -114,7 +114,6 @@ func resizePreserveAspectRatioHWC(t *ts.Tensor, outW int64, outH int64) (*ts.Ten
return nil, err
}
// TODO: check it
h := tsSize[1]
w := tsSize[0]
@ -146,12 +145,10 @@ func resizePreserveAspectRatioHWC(t *ts.Tensor, outW int64, outH int64) (*ts.Ten
tmpTs.MustDrop()
var tensorW *ts.Tensor
var delTensorW bool = false // Flag whether to delete tensorW to prevent memory leak.
if resizeW == outW {
tensorW = tsCHW
tensorW = tsCHW.MustShallowClone()
} else {
tensorW, err = tsCHW.Narrow(2, (resizeW-outW)/2, outW, false)
delTensorW = true
if err != nil {
err = fmt.Errorf("resizePreserveAspectRatioHWC - ts.Narrow() method call err: %v\n", err)
return nil, err
@ -169,9 +166,7 @@ func resizePreserveAspectRatioHWC(t *ts.Tensor, outW int64, outH int64) (*ts.Ten
return nil, err
}
if delTensorW {
tensorW.MustDrop()
}
tensorW.MustDrop()
return tensorH, nil
default: