Skip to content

test/erasure-code: fix memory leak when erasure_code_init() fails#64221

Merged
tchaikov merged 1 commit intoceph:mainfrom
tchaikov:wip-ec-test-fix-leak
Aug 4, 2025
Merged

test/erasure-code: fix memory leak when erasure_code_init() fails#64221
tchaikov merged 1 commit intoceph:mainfrom
tchaikov:wip-ec-test-fix-leak

Conversation

@tchaikov
Copy link
Contributor

Fix a memory leak in ErasureCodePluginExample when plugin registration fails. The allocated ErasureCodePluginExample instance was not being freed if ErasureCodePluginRegistry::add() failed, which occurs in tests that intentionally register duplicate plugins.

ASan detected the leak:

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7f4501321a2d in operator new(unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:86
    #1 0x7f4501a5914d in __erasure_code_init /home/kefu/dev/ceph/src/test/erasure-code/ErasureCodePluginExample.cc:44
    #2 0x5589985be68d in ceph::ErasureCodePluginRegistry::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>
> const&, ceph::ErasureCodePlugin**, std::ostream*) /home/kefu/dev/ceph/src/erasure-code/ErasureCodePlugin.cc:149
    #3 0x5589984984ee in ErasureCodePluginRegistryTest_all_Test::TestBody() /home/kefu/dev/ceph/src/test/erasure-code/TestErasureCodePlugin.cc:116

Use unique_ptr to manage the plugin instance lifecycle, following the pattern used by other erasure code plugins. The instance is now automatically destroyed if registry addition fails.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

Fix a memory leak in ErasureCodePluginExample when plugin registration
fails. The allocated ErasureCodePluginExample instance was not being
freed if ErasureCodePluginRegistry::add() failed, which occurs in tests
that intentionally register duplicate plugins.

ASan detected the leak:

```
Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7f4501321a2d in operator new(unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:86
    #1 0x7f4501a5914d in __erasure_code_init /home/kefu/dev/ceph/src/test/erasure-code/ErasureCodePluginExample.cc:44
    #2 0x5589985be68d in ceph::ErasureCodePluginRegistry::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>
> const&, ceph::ErasureCodePlugin**, std::ostream*) /home/kefu/dev/ceph/src/erasure-code/ErasureCodePlugin.cc:149
    #3 0x5589984984ee in ErasureCodePluginRegistryTest_all_Test::TestBody() /home/kefu/dev/ceph/src/test/erasure-code/TestErasureCodePlugin.cc:116
```

Use unique_ptr to manage the plugin instance lifecycle, following the
pattern used by other erasure code plugins. The instance is now
automatically destroyed if registry addition fails.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
@github-actions github-actions bot added the tests label Jun 27, 2025
@tchaikov tchaikov mentioned this pull request Jun 27, 2025
14 tasks
@tchaikov
Copy link
Contributor Author

jenkins test make check

@tchaikov
Copy link
Contributor Author

jenkins test api

@tchaikov
Copy link
Contributor Author

@ceph/core hello maintainers, could you please help review this change?

2 similar comments
@tchaikov
Copy link
Contributor Author

@ceph/core hello maintainers, could you please help review this change?

@tchaikov
Copy link
Contributor Author

tchaikov commented Aug 3, 2025

@ceph/core hello maintainers, could you please help review this change?

@tchaikov tchaikov merged commit a57b566 into ceph:main Aug 4, 2025
13 of 14 checks passed
@tchaikov tchaikov deleted the wip-ec-test-fix-leak branch August 4, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants