Skip to content

Fix memory leak in saveSnapshotToConnectionSockets#2503

Merged
zuiderkwast merged 2 commits into
valkey-io:unstablefrom
enjoy-binbin:fix_memo_leak
Aug 18, 2025
Merged

Fix memory leak in saveSnapshotToConnectionSockets#2503
zuiderkwast merged 2 commits into
valkey-io:unstablefrom
enjoy-binbin:fix_memo_leak

Conversation

@enjoy-binbin

Copy link
Copy Markdown
Member

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.

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

codecov Bot commented Aug 18, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.04%. Comparing base (f36cc20) to head (799d86c).
⚠️ Report is 5 commits behind head on unstable.

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     
Files with missing lines Coverage Δ
src/rdb.c 76.56% <100.00%> (-0.47%) ⬇️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zuiderkwast zuiderkwast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@zuiderkwast

Copy link
Copy Markdown
Contributor

@enjoy-binbin

Copy link
Copy Markdown
Member Author

that one was fixed in #2502

@zuiderkwast zuiderkwast merged commit 7a5c0d0 into valkey-io:unstable Aug 18, 2025
52 checks passed
@enjoy-binbin enjoy-binbin deleted the fix_memo_leak branch August 18, 2025 11:02
allenss-amazon pushed a commit to allenss-amazon/valkey-core that referenced this pull request Aug 19, 2025
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>
asagege pushed a commit to asagege/valkey that referenced this pull request Aug 19, 2025
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>
rjd15372 pushed a commit to rjd15372/valkey that referenced this pull request Sep 19, 2025
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>
rjd15372 pushed a commit that referenced this pull request Sep 23, 2025
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>
hpatro pushed a commit to hpatro/valkey that referenced this pull request Oct 3, 2025
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants