muktihari / fit

A FIT SDK for decoding and encoding Garmin FIT files in Go supporting FIT Protocol V2.
BSD 3-Clause "New" or "Revised" License
24 stars 2 forks source link

fix: slices clone related items #473

Closed muktihari closed 2 days ago

muktihari commented 2 days ago

Currently we use append(s[:0:0], s...) to clone a slice from an array pool. That approach comes with drawback if the slice happen to have zero len, the returning slice will share the same backing array of the array pool, causing array pool can not be freed until the returning slice become unreachable. More detail is declared here: https://github.com/golang/go/issues/68488#issuecomment-2378374828

This pattern was inspired from slices.Clone's CL that was first introduced in Go version v1.22.0. A new CL has been merged into Go's main branch to fix this issue but it seems without a backport request, so it might not be available until v1.24.0. If that's the case, people using v1.22.0 to v1.23.X are still being affected unless we do something about it. Since we typically clone a slice from an array pool, let's create our own clone function that better suite that case.

codecov-commenter commented 2 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.94%. Comparing base (85fb3b9) to head (f65c526). Report is 2 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #473 +/- ## ======================================= Coverage 99.94% 99.94% ======================================= Files 42 42 Lines 3689 3689 ======================================= Hits 3687 3687 Misses 2 2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.