Fix memory leak in saveSnapshotToConnectionSockets#2503
Conversation
We now pass in rdbSnapshotOptions options in this function, and options.conns is now malloc'ed in the caller side, so we need to zfree it when returning early due to an error. Previously, conns was malloc'ed after the error handling, so we don't have this. Introduced in valkey-io#1949. Signed-off-by: Binbin <binloveplay1314@qq.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #2503 +/- ##
============================================
+ Coverage 72.01% 72.04% +0.02%
============================================
Files 126 126
Lines 70448 70459 +11
============================================
+ Hits 50734 50759 +25
+ Misses 19714 19700 -14
🚀 New features to boost your workflow:
|
zuiderkwast
left a comment
There was a problem hiding this comment.
The top comment of this function has this comment:
* Connections array provided will be freed after the save is completed, and
* should not be freed by the caller. */We should update it to say that this array is freed by this function (success or failure doesn't matter). Maybe also clarify that it's the conns field in the rdbSnapshotOptions struct. It's also required that this array is heap allocated. Otherwise it can't be freed. Idea:
* The connections array (the conns field in the rdbSnapshotOptions) is a
* heap-allocated array that will be freed by this function and shall not be
* freed by the caller. */It's a little odd that this struct is passed by value, but it contains a heap-allocated array. Maybe we could use a different design, but the simple fix is just like this PR and to update the comment.
Signed-off-by: Binbin <binloveplay1314@qq.com>
|
Is it this leak seen in Daily today? https://github.com/valkey-io/valkey/actions/runs/17027650597/job/48265126023#step:6:7328 |
|
that one was fixed in #2502 |
We now pass in rdbSnapshotOptions options in this function, and options.conns is now malloc'ed in the caller side, so we need to zfree it when returning early due to an error. Previously, conns was malloc'ed after the error handling, so we don't have this. Introduced in valkey-io#1949. --------- Signed-off-by: Binbin <binloveplay1314@qq.com>
We now pass in rdbSnapshotOptions options in this function, and options.conns is now malloc'ed in the caller side, so we need to zfree it when returning early due to an error. Previously, conns was malloc'ed after the error handling, so we don't have this. Introduced in valkey-io#1949. --------- Signed-off-by: Binbin <binloveplay1314@qq.com>
We now pass in rdbSnapshotOptions options in this function, and options.conns is now malloc'ed in the caller side, so we need to zfree it when returning early due to an error. Previously, conns was malloc'ed after the error handling, so we don't have this. Introduced in valkey-io#1949. --------- Signed-off-by: Binbin <binloveplay1314@qq.com>
We now pass in rdbSnapshotOptions options in this function, and options.conns is now malloc'ed in the caller side, so we need to zfree it when returning early due to an error. Previously, conns was malloc'ed after the error handling, so we don't have this. Introduced in #1949. --------- Signed-off-by: Binbin <binloveplay1314@qq.com>
We now pass in rdbSnapshotOptions options in this function, and options.conns is now malloc'ed in the caller side, so we need to zfree it when returning early due to an error. Previously, conns was malloc'ed after the error handling, so we don't have this. Introduced in valkey-io#1949. --------- Signed-off-by: Binbin <binloveplay1314@qq.com> Signed-off-by: Harkrishn Patro <harkrisp@amazon.com>
We now pass in rdbSnapshotOptions options in this function, and options.conns
is now malloc'ed in the caller side, so we need to zfree it when returning early
due to an error. Previously, conns was malloc'ed after the error handling, so we
don't have this.
Introduced in #1949.