[SERVER-60157] Annotate mongoMalloc and mongoRealloc more aggressively Created: 22/Sep/21  Updated: 29/Oct/23  Resolved: 28/Sep/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.1.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: Andrew Morrow (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Dev Platform 2021-10-04
Participants:

 Description   

There are several things we can do to mongoMalloc and mongoRealloc to give the compiler more insight into the behavior of these functions:

  • Mark them as noexcept, since we know they never throw.
  • Mark them with the warn_unused_result or equivalent attribute, since failing to capture the result of a call indicates an unavoidable memory leak.
  • Mark them with the returns_nonnull or equivalent attribute, since they terminate on failure rather than returning nullptr.
  • Mark them with the alloc_size or equivalent attribute, so that for allocations of constexpr size the compiler can track the size of the allocated region and expose it via __builtin_object_size, improving bounds checking.
  • In the case of mongoMalloc, mark it with the malloc or equivalent attribute so that the compiler knows that the returned pointer cannot alias any existing object. Note that it is not appropriate to apply that attribute to mongoRealloc.

It may also make sense to mark reportOutOfMemoryErrorAndExit with the noreturn or equivalent attribute.



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 28/Sep/21 ]

Author:

{'name': 'Andrew Morrow', 'email': 'acm@mongodb.com', 'username': 'acmorrow'}

Message: SERVER-60157 Annotate mongoMalloc and mongoRealloc more aggressively
Branch: master
https://github.com/mongodb/mongo/commit/7771ad5741a409db9aed5d3da457711d30990cbf

Generated at Thu Feb 08 05:49:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.