]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
librbd/pwl: fix memory leaks in discard operations 66876/head
authorKefu Chai <k.chai@proxmox.com>
Tue, 17 Feb 2026 11:41:32 +0000 (19:41 +0800)
committerKefu Chai <k.chai@proxmox.com>
Sat, 21 Feb 2026 07:23:59 +0000 (15:23 +0800)
commitfcda31aba95043c1d344fd78c368d83409ccc763
treeed311e21b34312156f4e4a63e401155ca451374d
parent7eb1e7b478bae35f04b0b595f6e5c1e0a5b1f998
librbd/pwl: fix memory leaks in discard operations

Fix memory leak in librbd persistent write log (PWL) cache discard
operations by properly completing request objects.

ASan reported the following leaks in unittest_librbd:

  Direct leak of 240 byte(s) in 1 object(s) allocated from:
    #0 operator new(unsigned long)
    #1 librbd::cache::pwl::AbstractWriteLog<librbd::MockImageCtx>::discard(...)
       /ceph/src/librbd/cache/pwl/AbstractWriteLog.cc:935:5
    #2 TestMockCacheReplicatedWriteLog_discard_Test::TestBody()
       /ceph/src/test/librbd/cache/pwl/test_mock_ReplicatedWriteLog.cc:534:7

  Plus multiple indirect leaks totaling 2,076 bytes through the
  shared_ptr reference chain.

Root cause:

C_DiscardRequest objects were never deleted because their complete()
method was never called. The on_write_persist callback released the
BlockGuard cell but didn't call complete() to trigger self-deletion.

Write requests use WriteLogOperationSet which takes the request as
its on_finish callback, ensuring complete() is eventually called.
Discard requests don't use WriteLogOperationSet and must explicitly
call complete() in their on_write_persist callback.

Solution:

Call discard_req->complete(r) in the on_write_persist callback and
move cell release into finish_req() -- mirroring how C_WriteRequest
handles it. The complete() -> finish() -> finish_req() chain ensures
the cell is released after the user request is completed, preserving
the same ordering as write requests.

Test results:
- Before: 2,316 bytes leaked in 15 allocations
- After: 0 bytes leaked
- unittest_librbd discard tests pass successfully with ASan

Fixes: https://tracker.ceph.com/issues/74972
Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/librbd/cache/pwl/Request.cc
src/librbd/cache/pwl/Request.h