[SERVER-40495] Memory leak in BatchWriteOp Created: 05/Apr/19  Updated: 29/Oct/23  Resolved: 12/Apr/19

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 4.1.11

Type: Bug Priority: Major - P3
Reporter: Matthew Saltz (Inactive) Assignee: Randolph Tan
Resolution: Fixed Votes: 0
Labels: sharding-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:
Linked BF Score: 65

 Description   

Memory for a batch is allocated here using 'new', and is only deallocated when _cancelBatches is called.

In the code path added in a recent commit, there's a new early return which does not call _cancelBatches, compared to the adjacent branch below, which does.

_cancelBatches does need to be called in both places, and adding it to the new branch would fix the memory leak.

However, I don't see any reason we should be using raw pointers with memory allocated using 'new' here. We should probably either change this to use smart pointers or stack allocated memory so that we don't have to worry about introducing memory leaks accidentally in the future.



 Comments   
Comment by Githook User [ 12/Apr/19 ]

Author:

{'email': 'randolph@10gen.com', 'name': 'Randolph Tan', 'username': 'renctan'}

Message: SERVER-40495 Cleanup manually allocated memory inside BatchWriteOp::targetBatch on early return
Branch: master
https://github.com/mongodb/mongo/commit/fd2e3b54a3e3ad7daf1ce4f7ef6b6e125a6d2820

Generated at Thu Feb 08 04:55:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.