AdguardTeam / AdguardTeam/AdGuardHome
Potential Memory Leak due to Slice Expression
- 主要言語
- TypeScript
- スター
- 36.9k
- フォーク
- 2.5k
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
### Prerequisites
- [X] I have checked the [Wiki](https://github.com/AdguardTeam/AdGuardHome/wiki) and [Discussions](https://github.com/AdguardTeam/AdGuardHome/discussions/categories/q-a) and found no answer
- [X] I have searched other issues and found no duplicates
- [X] I want to report a bug and not [ask a question or ask for help](https://github.com/AdguardTeam/AdGuardHome/discussions/categories/q-a)
- [X] I have set up AdGuard Home correctly and [configured clients to use it](https://github.com/AdguardTeam/AdGuardHome/wiki/Clients). (Use the [Discussions](https://github.com/AdguardTeam/AdGuardHome/discussions/categories/q-a) for help with installing and configuring clients.)
### Platform (OS and CPU architecture)
Linux, AMD64 (aka x86_64)
### Installation
Other (please mention in the description)
### Setup
Other (please mention in the description)
### AdGuard Home version
other
### Action
Dear developers,
I used a self-written code linter to check the project and discovered a potential memory leak issue caused by a slice expression.
In the code shown as follows, before the slice expression `entries[params.offset:]`, the elements of `entries[0:params.offset]` are not set to nil. This could potentially cause the objects pointed to by each element of `entries[0:params.offset]` to be continuously referenced by the underlying array pointed to by the `entries` slice. As a result, these objects may not be garbage collected in a timely manner by the garbage collector. If `entries` is an object with a long lifetime, i.e., it needs to be used for a relatively long time, then there may be a hidden risk of memory leak.
https://github.com/AdguardTeam/AdGuardHome/blob/2c64ab5a5105098c0d4152e2b482d84d404c2086/internal/querylog/search.go#L125
```go
if params.offset > 0 {
if len(entries) > params.offset {
entries = entries[params.offset:]
} else {
entries = make([]*logEntry, 0)
oldest = time.Time{}
}
}
```
A possible solution is setting the elements of `entries[0:offset]` to nil before the slice expression. This way, the objects that are no longer needed after the slice expression can be properly garbage collected.
However, I am not sure if this is indeed a problem. I would greatly appreciate it if you can kindly confirm whether setting nil may cause wrong behaviors of the program.
Thank you for your time and efforts in reading this issue and maintaining the project.
### Expected result
set nil to `entries[0:params.offset]` before `entries[params.offset:]`
### Actual result
Currently the code does not set nil but I don't know whether set nil is correct.
### Additional information and/or screenshots
_No response_
コントリビューションガイド
評価
この issue はまだ評価されていません。