[SERVER-36345] Coverity analysis defect 104941: Pointer to local outside scope Created: 30/Jul/18  Updated: 29/Oct/23  Resolved: 01/Aug/18

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: None
Fix Version/s: 4.1.2

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: Tess Avitabile (Inactive)
Resolution: Fixed Votes: 0
Labels: coverity
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
is caused by SERVER-32906 Improve logging around elections Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Repl 2018-08-13
Participants:

 Description   

Pointer to a local stack variable returned or used outside scope

Defect 104941 (STATIC_C)
Checker RETURN_LOCAL (subcategory none)
File: /src/mongo/db/repl/topology_coordinator.cpp
Function _ZN5mongo4repl19TopologyCoordinator23_getReplSetStatusStringB5cxx11Ev
/src/mongo/db/repl/topology_coordinator.cpp, line: 1378
Assigning: "rsStatusArgs.initialSyncStatus" = "mongo::BSONObj()" (address of temporary variable of type "mongo::BSONObj").

        ReplSetStatusArgs rsStatusArgs{Date_t::now(), 0U, OpTime(), BSONObj(), boost::none};

/src/mongo/db/repl/topology_coordinator.cpp, line: 1378
Temporary variable of type "mongo::BSONObj" goes out of scope.

        ReplSetStatusArgs rsStatusArgs{Date_t::now(), 0U, OpTime(), BSONObj(), boost::none};

File: /src/mongo/db/repl/topology_coordinator.cpp
Function _ZN5mongo4repl19TopologyCoordinator23_getReplSetStatusStringB5cxx11Ev
/src/mongo/db/repl/topology_coordinator.cpp, line: 1378
Assigning: "rsStatusArgs.readConcernMajorityOpTime" = "mongo::repl::OpTime()" (address of temporary variable of type "mongo::repl::OpTime").

        ReplSetStatusArgs rsStatusArgs{Date_t::now(), 0U, OpTime(), BSONObj(), boost::none};

/src/mongo/db/repl/topology_coordinator.cpp, line: 1378
Temporary variable of type "mongo::repl::OpTime" goes out of scope.

        ReplSetStatusArgs rsStatusArgs{Date_t::now(), 0U, OpTime(), BSONObj(), boost::none};



 Comments   
Comment by Githook User [ 01/Aug/18 ]

Author:

{'username': 'tessavitabile', 'name': 'Tess Avitabile', 'email': 'tess.avitabile@mongodb.com'}

Message: SERVER-36345 ReplSetStatusArgs holds data members by value
Branch: master
https://github.com/mongodb/mongo/commit/fb8558b49bef476addb0ce9799362b5a4545220a

Comment by Eric Milkie [ 30/Jul/18 ]

The history of this code is fascinating. The reason that ReplSetStatusArgs exists with const ref members is because its data members used to be function parameters. Back in 2016, we moved these function parameters into a simple struct. Later, this simple struct would get a bit more complicated, with some const ref members going away, and some other boost::optional by-value parameters added.

Comment by Eric Milkie [ 30/Jul/18 ]

This appears to have happened because ReplSetStatusArgs is a simple struct with const-ref members, and a new use of this struct used it like a class with value members.

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