Skip to content

cephfs: free C.CString allocations in OpenSnapDiff#1254

Merged
mergify[bot] merged 1 commit into
ceph:masterfrom
lawrence3699:fix/free-cstring-allocations-in-snapdiff
May 11, 2026
Merged

cephfs: free C.CString allocations in OpenSnapDiff#1254
mergify[bot] merged 1 commit into
ceph:masterfrom
lawrence3699:fix/free-cstring-allocations-in-snapdiff

Conversation

@lawrence3699
Copy link
Copy Markdown

Summary

C.CString() allocates C heap memory that must be freed with C.free(). The 4 string allocations passed to open_snapdiff_dlsym() are never freed, causing a memory leak on every call. If the function returns early due to an error, all 4 strings leak.

Extracted each C.CString() into a named variable with a corresponding defer C.free().

Test plan

  • Existing snap_diff tests still pass
  • Verify with valgrind/ASAN that the leak is resolved

Copilot AI review requested due to automatic review settings April 2, 2026 05:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a C-heap memory leak in OpenSnapDiff by ensuring C.CString() allocations are freed after calling into the dynamically-loaded ceph_open_snapdiff wrapper.

Changes:

  • Extracted the four C.CString() calls in OpenSnapDiff into named variables.
  • Added defer C.free(...) for each allocated C string to guarantee cleanup on success and early-return error paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@anoopcs9 anoopcs9 added the API This PR includes a change to the public API of a go-ceph package label Apr 2, 2026
Copy link
Copy Markdown
Collaborator

@anoopcs9 anoopcs9 left a comment

Choose a reason for hiding this comment

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

Changes lgtm. See below for some process oriented suggestions:

  • Commit message title should mention the component in which the change is proposed. Please replace fix with cephfs.
  • Commit message is missing Signed-off-by: tag.

@anoopcs9
Copy link
Copy Markdown
Collaborator

@lawrence3699 Are you planning to work on my above request?

@phlogistonjohn
Copy link
Copy Markdown
Collaborator

@Mergifyio update

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 20, 2026

update

❌ Mergify doesn't have permission to update

Details

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/main.yml without workflows permission

@anoopcs9 anoopcs9 force-pushed the fix/free-cstring-allocations-in-snapdiff branch from 0fc99a8 to 5fcd5d0 Compare April 21, 2026 07:51
@anoopcs9 anoopcs9 changed the title fix: free C.CString allocations in OpenSnapDiff cephfs: free C.CString allocations in OpenSnapDiff Apr 21, 2026
@anoopcs9 anoopcs9 force-pushed the fix/free-cstring-allocations-in-snapdiff branch from 5fcd5d0 to 31cd264 Compare April 21, 2026 07:52
@anoopcs9
Copy link
Copy Markdown
Collaborator

@lawrence3699 Are you planning to work on my above request?

I've taken the liberty of rebasing (and fixing the commit‑message title) the PR. @lawrence3699, I'm still unsure which name and email address should appear in the Signed‑off‑by: line. Could you update it or let us know here?

@phlogistonjohn
Copy link
Copy Markdown
Collaborator

@anoopcs9 let's give @lawrence3699 two weeks to respond to your request for Sign-off. If @lawrence3699 is unable to respond by that time I suggest taking the patches into a branch we control and putting a Co-authored-by and then "owning" the patch ourselves with one of our sign offs. The patch is not trivial but it's not complex either and seems pretty straight forward.

I think that would be a good compromise in case lawrence3699 doesn't respond, WDYT?

@nixpanic
Copy link
Copy Markdown
Member

I think that would be a good compromise in case lawrence3699 doesn't respond, WDYT?

That is very reasonable. But for small changes like this I would reduce the time to a few days.

@phlogistonjohn
Copy link
Copy Markdown
Collaborator

Thanks for the suggestion. I had picked two weeks because it's a decent vacation length. :-)

@anoopcs9 anoopcs9 force-pushed the fix/free-cstring-allocations-in-snapdiff branch from 31cd264 to 2829d74 Compare May 7, 2026 06:23
Co-Authored-by: chaoliang yan (lawrence3699)
Signed-off-by: Anoop C S <anoopcs@cryptolab.net>
@anoopcs9 anoopcs9 force-pushed the fix/free-cstring-allocations-in-snapdiff branch from 2829d74 to e5c636c Compare May 7, 2026 06:27
@anoopcs9
Copy link
Copy Markdown
Collaborator

anoopcs9 commented May 7, 2026

@anoopcs9 let's give @lawrence3699 two weeks to respond to your request for Sign-off. If @lawrence3699 is unable to respond by that time I suggest taking the patches into a branch we control and putting a Co-authored-by and then "owning" the patch ourselves with one of our sign offs. The patch is not trivial but it's not complex either and seems pretty straight forward.

I think that would be a good compromise in case lawrence3699 doesn't respond, WDYT?

Given that the source branch is allowed to be updated by maintainers I've uploaded a modified version. Let me know whether we should proceed with the current branch or create a new one.

@phlogistonjohn
Copy link
Copy Markdown
Collaborator

Sounds good to me.

@anoopcs9 anoopcs9 requested a review from phlogistonjohn May 8, 2026 08:55
@phlogistonjohn
Copy link
Copy Markdown
Collaborator

Do we care about the failing pre-squid job? I think it's a packaging issue on the ceph side. But rather than just hit the approve button I felt I should double check.

@anoopcs9
Copy link
Copy Markdown
Collaborator

anoopcs9 commented May 9, 2026

Do we care about the failing pre-squid job? I think it's a packaging issue on the ceph side. But rather than just hit the approve button I felt I should double check.

I wanted to at least try and see what's wrong, but the squid tag isn't available at the moment. I can only agree that the earlier error is due to some packaging/build issue. Let's not wait any longer.

@mergify mergify Bot added the queued label May 11, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 11, 2026

Merge Queue Status

  • Entered queue2026-05-11 12:53 UTC · Rule: default
  • Checks skipped · PR is already up-to-date
  • Merged2026-05-11 12:53 UTC · at e5c636c1d7ed5974f4cc11d22a4bf2e097a57137 · rebase

This pull request spent 20 seconds in the queue, including 3 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = check
    • check-neutral = check
    • check-skipped = check
  • any of [🛡 GitHub branch protection]:
    • check-success = test-suite (pacific)
    • check-neutral = test-suite (pacific)
    • check-skipped = test-suite (pacific)
  • any of [🛡 GitHub branch protection]:
    • check-success = test-suite (quincy)
    • check-neutral = test-suite (quincy)
    • check-skipped = test-suite (quincy)
  • any of [🛡 GitHub branch protection]:
    • check-success = test-suite (reef)
    • check-neutral = test-suite (reef)
    • check-skipped = test-suite (reef)
  • any of [🛡 GitHub branch protection]:
    • check-success = test-suite (squid)
    • check-neutral = test-suite (squid)
    • check-skipped = test-suite (squid)

@mergify mergify Bot merged commit 98f6cb1 into ceph:master May 11, 2026
47 of 52 checks passed
@mergify mergify Bot removed the queued label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API This PR includes a change to the public API of a go-ceph package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants